<?php
/**
 * 古今玩小程序模块小程序接口定义
 *
 * @author 指尖团队
 * @url http://bbs.we7.cc/
 */
defined('IN_IA') or exit('Access Denied');

class Zh_gjwModuleWxapp extends WeModuleWxapp {
  	
	public function doPageGetaccesstoken(){
		global $_W, $_GPC;
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$appid=$res['appid'];
		$secret=$res['appsecret'];
		$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
		$data = curl_exec($ch);
		curl_close($ch);
		$data = json_decode($data,true);
		pdo_update('zh_gjw_system',array('accessToken'=>$data['access_token']),array('uniacid'=>$_W['uniacid']));
    }
  	
	
	//地摊中标付款，用户的系统保证金退还
	public function doPageUsysbzjbackd(){
		global $_W, $_GPC;
		include_once IA_ROOT . '/addons/zh_gjw/cert/WxPay.Api.php';
	    load()->model('account');
	    load()->func('communication');
	    $WxPayApi = new WxPayApi();
	    $input = new WxPayRefund();
	    $path_cert = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_cert_' . $_W['uniacid'] . '.pem';
	    $path_key = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
        function set_msg($_W,$id){
                $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
				$openid=pdo_get('zh_gjw_register',array('id'=>$id['u_id'],'uniacid'=>$_W['uniacid']));
                $formwork ='{
                      "touser": "'.$openid["openid"].'",
                      "template_id": "'.$ress["templeidbzj"].'",
                      "form_id":"'.$id['formid'].'",
                      "data": {
                          "keyword1": {
                              "value": "系统保证金退还",
                              "color": "#173177"
                          },
                          "keyword2": {
                              "value":"'.$id['fee'].'",
                              "color": "#173177"
                          }
                      }  
                }';
                $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL,$url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                curl_setopt($ch, CURLOPT_POST,1);
                curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
                $data = curl_exec($ch);
                curl_close($ch);
                return $data;
        }
		$syst=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$ress=pdo_fetchall("SELECT * FROM " . tablename('zh_gjw_sysbzjd'). " WHERE uniacid=:uniacid and time+INTERVAL 8760 HOUR>NOW() and pay=2", array(':uniacid'=>$_W['uniacid']));
		for ($i=0; $i <count($ress) ; $i++) {
			$user=pdo_get('zh_gjw_register',array('id'=>$ress[$i]['u_id']));
            $appid=$syst['appid'];
            $key=$syst['apikey'];
            $mchid=$syst['mac_id'];
            $out_trade_no=$ress[$i]['paycode'];//商户订单号
            $fee = $ress[$i]['fee'] * 100;
            $input->SetAppid($appid);
            $input->SetMch_id($mchid);
            $input->SetOp_user_id($mchid);
            $input->SetRefund_fee($fee);
            $input->SetTotal_fee($fee);
            $input->SetOut_refund_no($ress[$i]['paycode']);
            $input->SetOut_trade_no($out_trade_no);
            $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key);
            if ($result['result_code'] == 'SUCCESS') {//退款成功
                set_msg($_W,$ress[$i]);
                pdo_update('zh_gjw_sysbzjd',array('pay'=>3),array('id'=>$ress[$i]['id']));
                pdo_update('zh_gjw_marketbuy',array('tole'=>0),array('u_id'=>$ress[$i]['u_id']));
            }else{
                message($result['err_code_des'],'','error');
            }
		}
	}
	
	//微拍中标付款，用户的系统保证金退还
	public function doPageUsysbzjback(){
		global $_W, $_GPC;
		include_once IA_ROOT . '/addons/zh_gjw/cert/WxPay.Api.php';
	    load()->model('account');
	    load()->func('communication');
	    $WxPayApi = new WxPayApi();
	    $input = new WxPayRefund();
	    $path_cert = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_cert_' . $_W['uniacid'] . '.pem';
	    $path_key = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';

        function set_msg($_W,$id){
                //$access_token = getaccess_token($_W);
                $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
				$openid=pdo_get('zh_gjw_register',array('id'=>$id['u_id'],'uniacid'=>$_W['uniacid']));
                $formwork ='{
                      "touser": "'.$openid["openid"].'",
                      "template_id": "'.$ress["templeidbzj"].'",
                      "form_id":"'.$id['formid'].'",
                      "data": {
                          "keyword1": {
                              "value": "系统保证金退还",
                              "color": "#173177"
                          },
                          "keyword2": {
                              "value":"'.$id['fee'].'",
                              "color": "#173177"
                          }
                      }  
                }';
                $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL,$url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                curl_setopt($ch, CURLOPT_POST,1);
                curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
                $data = curl_exec($ch);
                curl_close($ch);
                return $data;
        }
		$syst=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$ress=pdo_fetchall("SELECT * FROM " . tablename('zh_gjw_sysbzj'). " WHERE uniacid=:uniacid and time+INTERVAL 8760 HOUR>NOW() and pay=2", array(':uniacid'=>$_W['uniacid']));
		for ($i=0; $i <count($ress) ; $i++) {
			$user=pdo_get('zh_gjw_register',array('id'=>$ress[$i]['u_id']));
            $appid=$syst['appid'];
            $key=$syst['apikey'];
            $mchid=$syst['mac_id'];
            $out_trade_no=$ress[$i]['paycode'];//商户订单号
            $fee = $ress[$i]['fee'] * 100;
            $input->SetAppid($appid);
            $input->SetMch_id($mchid);
            $input->SetOp_user_id($mchid);
            $input->SetRefund_fee($fee);
            $input->SetTotal_fee($fee);
            $input->SetOut_refund_no($ress[$i]['paycode']);
            $input->SetOut_trade_no($out_trade_no);
            $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key);
            if ($result['result_code'] == 'SUCCESS') {//退款成功
                set_msg($_W,$ress[$i]);
                pdo_update('zh_gjw_sysbzj',array('pay'=>3),array('id'=>$ress[$i]['id']));
                pdo_update('zh_gjw_balance',array('sysbzj'=>2),array('u_id'=>$ress[$i]['u_id']));
            }else{
                message($result['err_code_des'],'','error');
            }
		}
	}
  	
	//微拍中标不付款，用户的保证金给商家
	public function doPageUtosbzj(){
		global $_W, $_GPC;
		$ress=pdo_fetchall("SELECT * FROM " . tablename('zh_gjw_shotpublish'). " WHERE uniacid=:uniacid and shtime+INTERVAL 121 HOUR>NOW() and shtime+INTERVAL 120 HOUR<NOW()", array(':uniacid'=>$_W['uniacid']));
		for ($i=0; $i <count($ress) ; $i++) {
			$res=pdo_fetchall("SELECT * FROM " . tablename('zh_gjw_shotbuy'). " WHERE uniacid=:uniacid and shot_id=:shot_id and userbzj=1", array(':uniacid'=>$_W['uniacid'],'shot_id'=>$ress[$i]['id']));
			if($res){
				$cus=pdo_get('zh_gjw_cusmanage',array('phone'=>$ress[$i]['phone']));
				$data['u_id']=$res['u_id'];
				$data['c_id']=$cus['id'];
				$data['shot_id']=$ress[$i]['id'];
				$data['sysbzj']=1;
				$data['fee']=$ress[$i]['userbzj'];
				$data['uniacid']=$_W['uniacid'];
				$data['time']=date('Y-m-d H:i:s',time());
				$shotid=pdo_get('zh_gjw_balance',array('u_id'=>$res['u_id'],'c_id'=>$cus['id'],'shot_id'=>$ress[$i]['id']));
				if (empty($shotid)) {
					$insert=pdo_insert('zh_gjw_balance',$data);
					pdo_update('zh_gjw_sysbzj', array('pay' =>4), array('u_id' =>$res['u_id']));
				}
			}
		}
	}
  	//微拍退商家(没有人拍)、用户保证金(多人拍，不退最高的)
  	public function doPageBzj(){
		global $_W, $_GPC;
		include_once IA_ROOT . '/addons/zh_gjw/cert/WxPay.Api.php';
	    load()->model('account');
	    load()->func('communication');
	    $WxPayApi = new WxPayApi();
	    $input = new WxPayRefund();
	    $path_cert = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_cert_' . $_W['uniacid'] . '.pem';
	    $path_key = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
	    /*function getaccess_token($_W){
                $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
                $appid=$res['appid'];
                $secret=$res['appsecret'];
                $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL,$url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                $data = curl_exec($ch);
                curl_close($ch);
                $data = json_decode($data,true);
                return $data['access_token'];
        }*/
        function set_msg($_W,$id,$bzj){
                //$access_token = getaccess_token($_W);
                $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
                // $user=pdo_get('zh_gjw_dbpublish',array('id'=>$id));
                // $openid=pdo_get('zh_gjw_register',array('phone'=>$user['phone']));
						$openid=pdo_get('zh_gjw_register',array('id'=>$id['u_id'],'uniacid'=>$_W['uniacid']));
						$user=pdo_get('zh_gjw_shotpublish',array('id'=>$id['shot_id'],'uniacid'=>$_W['uniacid']));
                $formwork ='{
                      "touser": "'.$openid["openid"].'",
                      "template_id": "'.$ress["templeidbzj"].'",
                      "form_id":"'.$user['formid'].'",
                      "data": {
                          "keyword1": {
                              "value": "保证金退还",
                              "color": "#173177"
                          },
                          "keyword2": {
                              "value":"'.$bzj.'",
                              "color": "#173177"
                          }
                      }  
                }';
                $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL,$url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                curl_setopt($ch, CURLOPT_POST,1);
                curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
                $data = curl_exec($ch);
                curl_close($ch);
                return $data;
        }
        function set_msgs($_W,$res_id,$bzj){
            //$access_token = getaccess_token($_W);
            $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
            $openid=pdo_get('zh_gjw_register',array('id'=>$res_id['u_id']));
            $cusname=pdo_get('zh_gjw_cusmanage',array('openid'=>$openid['openid']));
            $formwork ='{
                "touser": "'.$openid["openid"].'",
                "template_id": "'.$ress["templeidbzj"].'",
                "form_id":"'.$res_id['formid'].'",
                "data": {
                    "keyword1": {
                        "value": "保证金退还",
                        "color": "#173177"
                    },
                    "keyword2": {
                        "value":"'.$bzj.'",
                        "color": "#173177"
                    }
                }  
            }';
            $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL,$url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
            curl_setopt($ch, CURLOPT_POST,1);
            curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
            $data = curl_exec($ch);
            curl_close($ch);
           return $data;
        }
		// $res=pdo_fetchall("SELECT * FROM " . tablename('zh_gjw_shotbuy'). " WHERE uniacid=:uniacid and userbzj=1 and pay=0", array(':uniacid'=>$_W['uniacid']));
		function ressort($shots){
              for($i=1;$i<count($shots);$i++)
               { //该层循环用来控制每轮 冒出一个数 需要比较的次数
                  for($k=0;$k<count($shots)-$i;$k++)
                  {
                     if($shots[$k]['fee']<$shots[$k+1]['fee'])
                      {
                          $tmp=$shots[$k+1];
                          $shots[$k+1]=$shots[$k];
                          $shots[$k]=$tmp;
                      }
                  }
              }
          return $shots;
        }
		$ress=pdo_fetchall("SELECT * FROM " . tablename('zh_gjw_shotpublish'). " WHERE uniacid=:uniacid and shtime+INTERVAL 73 HOUR>NOW() and shtime+INTERVAL 72 HOUR<NOW()", array(':uniacid'=>$_W['uniacid']));
		for ($i=0; $i <count($ress) ; $i++) {
			$res=pdo_fetchall("SELECT * FROM " . tablename('zh_gjw_shotbuy'). " WHERE uniacid=:uniacid and shot_id=:shot_id and userbzj=1", array(':uniacid'=>$_W['uniacid'],'shot_id'=>$ress[$i]['id']));
			if (empty($res)) {
				//没有人拍，退商家保证金
				$syst=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
	            $appid=$syst['appid'];
	            $key=$syst['apikey'];
	            $mchid=$syst['mac_id'];
	            $out_trade_no=$ress[$i]['paycode'];//商户订单号
	            $fee = $ress[$i]['bzj'] * 100;
	            $input->SetAppid($appid);
	            $input->SetMch_id($mchid);
	            $input->SetOp_user_id($mchid);
	            $input->SetRefund_fee($fee);
	            $input->SetTotal_fee($ress[$i]['payfee']);
	            $input->SetOut_refund_no($ress[$i]['paycode']);
	            $input->SetOut_trade_no($out_trade_no);
	            $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key);
	            if ($result['result_code'] == 'SUCCESS') {//退款成功
	                set_msgs($_W,$res[$i],$ress[$i]['bzj']);
	                pdo_update('zh_gjw_shotpublish',array('bzjstate'=>1),array('id'=>$ress[$i]['id']));
	            }else{
	                message($result['err_code_des'],'','error');
	            }
			}else{
				//有人拍,
				if (count($res)>1) {//且不止一个
					$res=ressort($res);
					$res=array_splice($res,0,1);
					for ($j=0; $j <count($res) ; $j++) { 
						//退没有拍到拍品的用户保证金
						$userbzj=pdo_get('zh_gjw_shotpublish',array('id'=>$res[$j]['shot_id'],'uniacid'=>$_W['uniacid']));
						$syst=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
			            $appid=$syst['appid'];
			            $key=$syst['apikey'];
			            $mchid=$syst['mac_id'];
			            $out_trade_no=$res[$j]['paycode'];//商户订单号
			            $fee = $userbzj['userbzj'] * 100;
			            $input->SetAppid($appid);
			            $input->SetMch_id($mchid);
			            $input->SetOp_user_id($mchid);
			            $input->SetRefund_fee($fee);
			            $input->SetTotal_fee($fee);
			            $input->SetOut_refund_no($res[$j]['paycode']);
			            $input->SetOut_trade_no($out_trade_no);
			            $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key);
			            if ($result['result_code'] == 'SUCCESS') {//退款成功
			                set_msg($_W,$res[$j],$fee);
			                pdo_update('zh_gjw_shotbuy',array('userbzj'=>2),array('id'=>$res[$j]['id']));
			            }else{
			                message($result['err_code_des'],'','error');
			            }
					}
				}else{//只有一个
					exit();
				}
			}

		}
		
		if ($res) {
			echo json_encode(array('msg'=>'成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'失败','code'=>'500'),320);exit();

	}
	//获取openid
	public function doPageOpenid(){
		global $_W, $_GPC;
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$code=$_GPC['code'];
		$appid=$res['appid'];
		$secret=$res['appsecret'];
	// echo $appid;die;
		$url="https://api.weixin.qq.com/sns/jscode2session?appid=".$appid."&secret=".$secret."&js_code=".$code."&grant_type=authorization_code";
		function httpRequest($url,$data = null){
			$curl = curl_init();
			curl_setopt($curl, CURLOPT_URL, $url);
			curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
			curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
			if (!empty($data)){
				curl_setopt($curl, CURLOPT_POST, 1);
				curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
			}
			curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		//执行
			$output = curl_exec($curl);
			curl_close($curl);
			return $output;
		}
		$res=httpRequest($url);
		print_r($res);
	}
	//游客记录
	public function doPageVisit(){
        global $_W, $_GPC;
        $openid=pdo_get('zh_gjw_visit',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
        if ($openid) {
        	echo json_encode(array('msg'=>'游客存在','code'=>'201'),320);exit();
        }else{
        	$data['openid']=$_GPC['openid'];
			$data['avatar']=$_GPC['avatar'];
			$data['nickname']=$_GPC['nickname'];
			$data['uniacid']=$_W['uniacid'];
			$data['time']=date('Y-m-d H:i:s',time());
			$res=pdo_insert('zh_gjw_visit',$data);
			if ($res) {
        		echo json_encode(array('msg'=>'记录成功','code'=>'200','res'=>$res),320);exit();
			}else{
				echo json_encode(array('msg'=>'记录失败','code'=>'500'),320);exit();
			}
        }
    }
	/**
	*获得图片路径（七牛云）
	*/
	public function doPageAttachurl(){
		global $_W;
	 	echo json_encode($_W['attachurl'],320);exit();
	}
	//站点
	public function doPageSiteurl(){
		global $_GPC, $_W;
		echo json_encode($_W['siteroot'],320);exit();
	}
	//模块标识
	public function doPageUniacid(){
		global $_GPC, $_W;
		echo json_encode($_W['uniacid'],320);exit();
	}
	/**
	*logo
	*/
	public function doPageLogo(){
		global $_W;
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res['img']),320);exit();
	}
	//帮助中心
	public function doPageHelp(){
		global $_GPC, $_W;
		$res=pdo_getall('zh_gjw_help',array('state'=>1,'uniacid'=>$_W['uniacid']), array() , '' , 'sort ASC' , array());
		echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res),320);exit();
	}
	/**
	*客服电话
	*/
	public function doPageSertel(){
		global $_W;
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res['tel']),320);exit();
	}
	/**
	*审核是否开启状态
	*/
	public function doPageShset(){
		global $_W;
		$res=pdo_get('zh_gjw_shset',array('uniacid'=>$_W['uniacid']));
		echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res),320);exit();
	}
	//没用的玩的
	public function doPageBaseEncode(){
		global $_W, $_GPC;
		load()->func('tpl');
		function  getCoade($id){
			/*function getaccess_token(){
				global $_W, $_GPC;
				$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
				$appid=$res['appid'];
				$secret=$res['appsecret'];			
	          // $appid="wx648013d2ed95099f";
	          // $secret="37a58d68f3e94cffd2fea40c5add670a";
				$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
				$ch = curl_init();
				curl_setopt($ch, CURLOPT_URL,$url);
				curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
				curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
				$data = curl_exec($ch);
				curl_close($ch);
				$data = json_decode($data,true);
				return $data['access_token'];
			}*/
			function set_msg($id){
				$ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
				//$access_token = getaccess_token();
				$data2=array(
					"scene"=>$id,
					// "page"=>"/zh_tc/pages/index?query=1",
					"width"=>300
					);
				$data2 = json_encode($data2);
				$url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=".$ress['accessToken']."";
				$ch = curl_init();
				curl_setopt($ch, CURLOPT_URL,$url);
				curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
				curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
				curl_setopt($ch, CURLOPT_POST,1);
				curl_setopt($ch, CURLOPT_POSTFIELDS,$data2);
				$data = curl_exec($ch);
				curl_close($ch);
				return $data;
			}
			$img=set_msg($id);
			$img=base64_encode($img);
			return $img;
		}
		echo getCoade($_GPC['id']);
	} 
	//注册
	public function doPageRegister(){
        global $_W, $_GPC;
	    $grade=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
        $openid=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
        if (empty($openid)) {
			$data['openid']=$_GPC['openid'];
			$data['avatar']=$_GPC['avatar'];
			$data['phone']=$_GPC['phone'];
			$data['username']=$_GPC['username'];
			$data['level_name']= $grade['ugrade'];
			$data['uniacid']=$_W['uniacid'];
			$data['time']=date('Y-m-d H:i:s',time());
			$res=pdo_insert('zh_gjw_register',$data);
        	if ($res) {
        		echo json_encode(array('msg'=>'注册成功','code'=>'200','res'=>$res),320);exit();
			}else{
				echo json_encode(array('msg'=>'注册失败','code'=>'500'),320);exit();
			}
        }else{
        	echo json_encode(array('msg'=>'该用户已经注册过','code'=>'201'),320);exit();
        }
    }
    /**
	*发送手机验证码
	**/
	public function doPageCode(){
	    global $_GPC,$_W;
	    include IA_ROOT.'/addons/zh_gjw/SendCode.php';
	    $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
	    // var_dump($res);die;
	    $appkey=$res['appkey'];//聚合appkey
	    $phone=$_GPC['phone'];//接过来的手机号
	    $tpl_id=$res['tpl_id'];//短信模板id
	    // $str = '3456789abdefghjkmnpswqxyrt';//验证码字符串
        // $code = substr(str_shuffle($str),0,6);
        $code = $_GPC['code'];
	    $tpl_value=urlencode('#code#'."=".$code);//模板变量
	    // $tpl_value=urlencode($res['tpl_value']);//模板变量
	    if (empty($_GPC['phone'])) {
	    	echo json_encode(array('msg'=>'手机号不能为空','code'=>'500'),320);exit();
	    }
	    if (!preg_match('/^1[34578]\d{9}$/',$phone)) {
	    	echo json_encode(array('msg'=>'请输入正确的手机号','code'=>'501'),320);exit();
	    }
	    $results = new SendCode($appkey,$phone,$tpl_id,$tpl_value);
	    $return=$results->code();
	    if($return){
		    $result = json_decode($return,true);
		    $error_code = $result['error_code'];
		    if($error_code == 0){
		        //状态为0，说明短信发送成功
		        // pdo_insert('snx_code',array('code'=>$code,'phone'=>$phone,'create_time'=>date('Y-m-d H:i:s',time())));
		        echo json_encode(array('msg'=>'发送成功','code'=>$result['result']['sid']),320);exit();
		    }else{
		        //状态非0，说明失败
		        $msg = $result['reason'];
		        echo json_encode(array('msg'=>$msg,'code'=>$error_code),320);exit();
		    }
		}else{
		    //返回内容异常，以下可根据业务逻辑自行修改
		    echo "请求发送短信失败";
		}
	}
	//上传图片
    public function doPageUploads(){
        global $_W, $_GPC;
        $destination_folder="../attachment/images/".$_W['uniacid']."/".date(Y)."/".date(m)."/";
        $imgmurl="images/".$_W['uniacid']."/".date(Y)."/".date(m)."/";
        if(!file_exists($destination_folder)) //如果文件(夹)不存在
        {
            mkdir($destination_folder,0777); //创建对应文件(夹),并设置权限为全部可读可写可操作
        }
        chmod($destination_folder , 0777);
        if (!file_exists($_FILES['upload_file']['name'])) {
        	
        	move_uploaded_file($_FILES['upload_file']['tmp_name'], $destination_folder.$_FILES['upload_file']['name']);
        }
        echo $imgmurl.$_FILES['upload_file']['name'];exit();
    }
    //上传视频

	public function doPageUploadvideo(){
	    global $_W, $_GPC;
	    $destination_folder="../attachment/videos/".$_W['uniacid']."/".date(Y)."/".date(m)."/";
        $videomurl="videos/".$_W['uniacid']."/".date(Y)."/".date(m)."/";
        if(!file_exists($destination_folder)) //如果文件(夹)不存在
        {	
            mkdir($destination_folder,0777,true); //创建对应文件(夹),并设置权限为全部可读可写可操作
        }
        chmod($destination_folder , 0777);
        if (!file_exists($_FILES['upload_file']['name'])) {
        	
        	move_uploaded_file($_FILES['upload_file']['tmp_name'], $destination_folder.$_FILES['upload_file']['name']);
        }
        echo $videomurl.$_FILES['upload_file']['name'];exit();
    }
    //分类级数
	public function doPageCatelevel(){
		global $_GPC, $_W;
		$res=pdo_get('zh_gjw_catelevel',array('uniacid'=>$_W['uniacid']));
		if ($res) {
			echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res['marketcate']),320);exit();
		}
		echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
	}

	//抖宝分类
	public function doPageDbcate(){
		global $_GPC, $_W;
		$res=pdo_getall('zh_gjw_dbcate',array('showhide'=>1,'uniacid'=>$_W['uniacid']), array() , '' , 'sort ASC' , array());
		if ($res) {
			echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
	}
  //微拍一二三级分类数组
	public function doPageCateott(){
		global $_GPC, $_W;
		$res=pdo_getall('zh_gjw_marketcate',array('showhide'=>1,'uniacid'=>$_W['uniacid'],'p_id'=>0), array() , '' , 'sort ASC' , array());
		for ($i=0; $i <count($res) ; $i++) { 
			$res[$i]['arr']=array();
			$res[$i]['arr']=pdo_getall('zh_gjw_marketcate',array('showhide'=>1,'uniacid'=>$_W['uniacid'],'p_id'=>$res[$i]['id']), array() , '' , 'id ASC' , array());
			for ($j=0; $j <count($res[$i]['arr']) ; $j++) { 
				$res[$i]['arr'][$j]['sarr']=array();
				$res[$i]['arr'][$j]['sarr']=pdo_getall('zh_gjw_marketcate',array('showhide'=>1,'uniacid'=>$_W['uniacid'],'p_id'=>$res[$i]['arr'][$j]['id']), array() , '' , 'id ASC' , array());
			}

		}
		echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res),320);exit();
	}
	//微拍分类
	public function doPageShotcate(){
		global $_GPC, $_W;
		$res=pdo_getall('zh_gjw_shotcate',array('showhide'=>1,'uniacid'=>$_W['uniacid']), array() , '' , 'sort ASC' , array());
		if ($res) {
			echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
	}
	//地摊分类
	public function doPageMarketcate(){
		global $_GPC, $_W;
		$res=pdo_getall('zh_gjw_marketcate',array('showhide'=>1,'uniacid'=>$_W['uniacid']), array() , '' , 'sort ASC' , array());
		if ($res) {
			echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
	}
	//定制分类
	public function doPagePricate(){
		global $_GPC, $_W;
		$res=pdo_getall('zh_gjw_pricate',array('showhide'=>1,'uniacid'=>$_W['uniacid']), array() , '' , 'sort ASC' , array());
		if ($res) {
			echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
	}

	//所有级分类
	public function doPageCates(){
		global $_GPC, $_W;
		$res=pdo_getall('zh_gjw_marketcate',array('showhide'=>1,'uniacid'=>$_W['uniacid']), array() , '' , 'sort ASC' , array());
		if ($res) {
			echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
	}
	//所有级分类之顶级
	public function doPageCatestop(){
		global $_GPC, $_W;
		$res=pdo_getall('zh_gjw_marketcate',array('showhide'=>1,'uniacid'=>$_W['uniacid'],'p_id'=>0), array() , '' , 'sort ASC' , array());
		if ($res) {
			echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
	}
	//所有级分类之次级
	public function doPageCatessub(){
		global $_GPC, $_W;
		$res=pdo_getall('zh_gjw_marketcate',array('showhide'=>1,'uniacid'=>$_W['uniacid'],'p_id'=>$_GPC['pid']), array() , '' , 'sort ASC' , array());
		if ($res) {
			echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
	}
	//商家费用
	public function doPageCusmoney(){
		global $_GPC,$_W;
    	$cusmoney=pdo_get('zh_gjw_cusmoney',array('uniacid'=>$_W['uniacid']));
    	if (empty($cusmoney)) {
    		echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
    	}elseif($cusmoney){
    		echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$cusmoney),320);exit();
    	}
	}

	//商家入驻
	public function doPageCusmanage(){
        global $_W, $_GPC;
        $grade=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
        $openidr=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
        if (empty($openidr)) {
			$datar['openid']=$_GPC['openid'];
			$datar['avatar']=$_GPC['avatar'];
			$datar['phone']=$_GPC['phone'];
			$datar['username']=$_GPC['username'];
			$datar['level_name']= $grade['ugrade'];
			$datar['uniacid']=$_W['uniacid'];
			$datar['time']=date('Y-m-d H:i:s',time());
			pdo_insert('zh_gjw_register',$datar);
		}
        $phone=pdo_get('zh_gjw_cusmanage',array('phone'=>$_GPC['phone'],'uniacid'=>$_W['uniacid']));
        if ($phone) {
        	echo json_encode(array('msg'=>'该手机号存在','code'=>'202'),320);exit();
        }
        $avatar=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
        $openid=pdo_get('zh_gjw_cusmanage',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));

        /*function getaccess_token($_W){
          $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
          $appid=$res['appid'];
          $secret=$res['appsecret'];
          $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL,$url);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
          $data = curl_exec($ch);
          curl_close($ch);
          $data = json_decode($data,true);
          return $data['access_token'];
        }*/
        function set_msgs($_W,$res_id){
            //$access_token = getaccess_token($_W);
            $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
            $openid=pdo_get('zh_gjw_cusmanage',array('id'=>$res_id));
            $formwork ='{
                "touser": "'.$openid["openid"].'",
                "template_id": "'.$ress["templeid"].'",
                "form_id":"'.$openid['formid'].'",
                "data": {
                    "keyword1": {
                        "value": "'.$openid['cusname'].'",
                        "color": "#173177"
                    },
                    "keyword2": {
                        "value":"商家认证审核通过",
                        "color": "#173177"
                    }
                }  
            }';
            $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL,$url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
            curl_setopt($ch, CURLOPT_POST,1);
            curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
            $data = curl_exec($ch);
            curl_close($ch);
           return $data;
        }

        if (empty($openid)) {
			$data['type']=$_GPC['type'];
			$data['shot_id']=$_GPC['shot_id'];
			$data['shotcate']=$_GPC['shotcate'];
			$data['cusname']=$_GPC['cusname'];
			$data['cusaddress']=$_GPC['cusaddress'];
			$data['addressdetail']=$_GPC['addressdetail'];
			$data['username']=$_GPC['username'];
			$data['phone']=$_GPC['phone'];
			$data['liceneimg']=$_GPC['liceneimg'];
			$data['cardimg']=$_GPC['cardimg'];
			$data['storeimg']=$_GPC['storeimg'];
			$data['formid']=$_GPC['formid'];
			$data['sh']=1;
			$data['openid']=$_GPC['openid'];
			$data['avatar']=$avatar['avatar'];
			$data['password']=$_GPC['password'];
			$data['level_name']=$grade['cgrade'];
			$data['reputation']= $grade['xygrade'];
			$data['uniacid']=$_W['uniacid'];
			$data['time']=date('Y-m-d H:i:s',time());
			$res=pdo_insert('zh_gjw_cusmanage',$data);
			$res_id=pdo_insertid();
        	if ($res) {
        		$shset=pdo_get('zh_gjw_shset',array('uniacid'=>$_W['uniacid']));
	    		if ($shset['cusshset']!=1) {
	    			set_msgs($_W,$res_id);
	    			 $refund_order =pdo_get('zh_gjw_cusmanage',array('id'=>$res_id));  
	    			$user['username']=$refund_order['phone'];
			        $user['password']=$refund_order['password'];
			        $user['salt'];
			        $uid = user_register($user,null);
			        if ($uid > 0) {
			            unset($user['password']);
			            $data = array(
			                'uniacid' => $_W['uniacid'],
			                'uid' => $uid,
			                'role' => 'operator',
			            );
			            $exists = pdo_fetch("SELECT * FROM " . tablename('uni_account_users') . " WHERE uid = :uid AND uniacid = :uniacid", array(':uniacid' => $_W['uniacid'], ':uid' => $uid));
			            if (empty($exists)) {
			                pdo_insert('uni_account_users', $data);
			            }
			            //permission
			            pdo_insert('users_permission', array(
			                'uid' => $uid,
			                'uniacid' => $_W['uniacid'],
			                'url' => '',
			                'type' => 'zh_gjw',
			                // 'permission' => 'zh_zhjz_menu_store'
			            ));
			        }
	    			pdo_update('zh_gjw_cusmanage', array('sh' =>2), array('id' =>$res_id,'uniacid'=>$_W['uniacid']));

	    			echo json_encode(array('msg'=>'注册成功','code'=>'203','res_id'=>$res_id),320);exit();
	    		}
	    		echo json_encode(array('msg'=>'注册成功','code'=>'200','res_id'=>$res_id),320);exit();
	    		
			}else{
				echo json_encode(array('msg'=>'注册失败','code'=>'500'),320);exit();
			}
        }else{
        	echo json_encode(array('msg'=>'该用户已经注册过','code'=>'201'),320);exit();
        }
    }
    //商家认证支付
	public function doPageCuspay(){
		global $_W, $_GPC;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$res_fee=$_GPC['publishfee'];
		// if ($_GPC['upstate']==1) {
		// 	$res_fee=$res_fee+$_GPC['upfee'];
		// }
		// if ($_GPC['topstate']==1) {
		// 	$res_fee=$res_fee+$_GPC['topfee'];
		// }
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		pdo_update('zh_gjw_cusmanage', array('paycode' =>$out_trade_no), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		$root=$_W['siteroot']; 
		$total_fee =$res_fee;
		if($total_fee>0)
		{
			$body = "商家认证";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
		echo json_encode($return);
	}

	//商家认证支付改变状态
	public function doPageCuspaysuccess(){
		global $_W, $_GPC;
    	$cusmoney=pdo_get('zh_gjw_cusmoney',array('uniacid'=>$_W['uniacid']));
    	$type=pdo_get('zh_gjw_cusmanage',array('id'=>$_GPC['res_id']));
		if ($type==1) {
			$res = pdo_update('zh_gjw_cusmanage', array('payfee' => $cusname['dpublishfee'],'pay' => 1,'paytime' =>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		}else{
			$res = pdo_update('zh_gjw_cusmanage', array('payfee' => $cusname['publishfee'],'pay' => 1,'paytime' =>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		}
		echo json_encode(array('msg'=>'嗨','code'=>'200','res'=>$res),320);exit();
	}
    //商家登录
    public function doPageCuslogin(){
    	global $_GPC,$_W;
    	$login=pdo_get('users',array('username'=>$_GPC['admin']));
    	if (empty($login)) {
    		echo json_encode(array('msg'=>'不存在该账号,未认证为商家或正在审核...','code'=>'201'),320);exit();
    	}else{
    		$password=pdo_get('zh_gjw_cusmanage',array('phone'=>$_GPC['admin'],'uniacid'=>$_W['uniacid']));
    		if ($password['password']==$_GPC['password']) {
    			echo json_encode(array('msg'=>'登录成功','code'=>'200'),320);exit();
    		}else{
    			echo json_encode(array('msg'=>'账号与密码不符','code'=>'500'),320);exit();
    		}
    	}
    }
    //店铺名称
    public function doPageCusname(){
    	global $_GPC,$_W;
    	$cusname=pdo_get('zh_gjw_cusmanage',array('phone'=>$_GPC['admin'],'uniacid'=>$_W['uniacid']));
    	$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $cusname['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
      	$cusnameorder=pdo_getall('zh_gjw_orders',array('cus_id'=>$cusname['id'],'uniacid'=>$_W['uniacid'],'state'=>4), array() , '' , 'id ASC' , array());
      	$desstars=0;
      	$speedstars=0;
      	$total=0;
      	for ($i=0; $i <count($cusnameorder) ; $i++) { 
	    	$stars=pdo_get('zh_gjw_orderassess',array('p_id'=>$cusnameorder[$i]['id'],'uniacid'=>$_W['uniacid']));
	    	if ($stars) {
		    	$desstars+=$stars['desstar'];
		    	$speedstars+=$stars['speedstar'];
      			$total+=1;
	    	}

      	}
    	if (empty($cusname)) {
    		echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
    	}elseif($cusname){
          if($statrs){
    		$cusname['stars']=ceil(($desstars+$speedstars)/(2*$total));
          }
    		$cusname['xybzj']=$totalmoney['total_money'];
    		echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$cusname),320);exit();
    	}
    }
    //抖宝费
    public function doPageDbmoney(){
    	global $_GPC,$_W;
    	$dbmoney=pdo_get('zh_gjw_dbmoney',array('uniacid'=>$_W['uniacid']));
    	if (empty($dbmoney)) {
    		echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
    	}elseif($dbmoney){
    		echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$dbmoney),320);exit();
    	}
    }
    //发布抖宝
    public function doPageDbpublish(){
    	global $_GPC,$_W;
    	$openid=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$data['formid']=$_GPC['formid'];
		$data['video']=$_GPC['video'];
		$data['videoimg']=$_GPC['videoimg'];
		$data['c_id']=$_GPC['c_id'];
		$data['dbname']=$_GPC['dbname'];
		$data['dbfee']=$_GPC['dbfee'];
		$data['exfee']=$_GPC['exfee'];
		$data['detail']=$_GPC['detail'];
		$data['openid']=$_GPC['openid'];
		$data['phone']=$openid['phone'];
		$data['avatar']=$openid['avatar'];
		$data['username']=$openid['username'];
		$data['state']=1;
		$data['uniacid']=$_W['uniacid'];
		$data['time']=date('Y-m-d H:i:s',time());
		$res=pdo_insert('zh_gjw_dbpublish',$data);
		$res_id=pdo_insertid();
		
    	if ($res) {
    		echo json_encode(array('msg'=>'记录成功','code'=>'200','res'=>$res,'res_id'=>$res_id),320);exit();
		}else{
			echo json_encode(array('msg'=>'记录失败','code'=>'500'),320);exit();
		}
    }

    //抖宝支付
	public function doPageDbpay(){
		global $_W, $_GPC;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$res_fee=0;
    	$shset=pdo_get('zh_gjw_shset',array('uniacid'=>$_W['uniacid']));
    	if ($shset['dbshset']==1) {
	    	if ($_GPC['upstate']==1) {
	    		if($_GPC['publishfee']>0){
	    			$res_fee=$_GPC['publishfee']+$_GPC['upfee'];
	    		}else{
	    			$res_fee=$_GPC['upfee'];
	    		}
			}else{
				if($_GPC['publishfee']>0){
	    			$res_fee=$_GPC['publishfee'];
	    		}else{
	    			$res_fee=0;
	    		}
			}
    	}elseif ($shset['dbshset']!=1) {
    		if ($_GPC['upstate']==1) {
	    		if($_GPC['publishfee']>0){
	    			$res_fee=$_GPC['publishfee']+$_GPC['upfee'];
	    		}else{
	    			$res_fee=$_GPC['upfee'];
	    		}
			}else{
				if($_GPC['publishfee']>0){
	    			$res_fee=$_GPC['publishfee'];
	    		}else{
	    			$res_fee=0;
	    		}
			}
    	}
    	if ($_GPC['alltype']==14) {
    		$res_fee=$res_fee-$_GPC['upfee'];
    	}
    	if ($_GPC['alltype']==18) {
    		$res_fee=$res_fee-$_GPC['publishfee'];
    	}
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		pdo_update('zh_gjw_dbpublish', array('paycode' =>$out_trade_no), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		$root=$_W['siteroot']; 
		$total_fee =$res_fee;
		if($total_fee>0)
		{
			$body = "抖宝发布";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
		echo json_encode($return);
	}

	//抖宝支付成功改变state
	public function doPageDbsuccess(){
		global $_W, $_GPC;
      	
		file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=GetGradedbp&m=zh_gjw&order_id=" . $_GPC['res_id']);//修改等级
		/*function getaccess_token($_W){
          $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
          $appid=$res['appid'];
          $secret=$res['appsecret'];
          $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL,$url);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
          $data = curl_exec($ch);
          curl_close($ch);
          $data = json_decode($data,true);
          return $data['access_token'];
        }*/
        function set_msg($_W,$id){
            //$access_token = getaccess_token($_W);
            $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
            $openid=pdo_get('zh_gjw_dbpublish',array('id'=>$id));
            $formwork ='{
                "touser": "'.$openid["openid"].'",
                "template_id": "'.$ress["templeid"].'",
                "form_id":"'.$openid['formid'].'",
                "data": {
                    "keyword1": {
                        "value": "'.$openid['dbname'].'",
                        "color": "#173177"
                    },
                    "keyword2": {
                        "value":"抖宝审核通过",
                        "color": "#173177"
                    }
                }  
            }';
            $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL,$url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
            curl_setopt($ch, CURLOPT_POST,1);
            curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
            $data = curl_exec($ch);
            curl_close($ch);
           return $data;
        }
    	$shset=pdo_get('zh_gjw_shset',array('uniacid'=>$_W['uniacid']));
    	$dbmoney=pdo_get('zh_gjw_dbmoney',array('uniacid'=>$_W['uniacid']));
    	if ($shset['dbshset']==1) {
			if ($_GPC['upstate']==1) {
				if ($dbmoney['publishfee']>0) {
					$allmoney=$dbmoney['publishfee']+$dbmoney['upfee'];
					if ($_GPC['alltype']==14) {
						pdo_update('zh_gjw_dbpublish', array('type' => 14,'pay' => 1,'upfee' =>1,'payfee'=>$dbmoney['publishfee']), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=7;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==18) {
						pdo_update('zh_gjw_dbpublish', array('type' => 18,'pay' => 1,'upfee' =>1,'payfee'=>$dbmoney['upfee']), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=1;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==22) {
						pdo_update('zh_gjw_dbpublish', array('type' => 22,'pay' => 1,'upfee' =>1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=1;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
						$datas['openid']=$_GPC['openid'];
						$datas['type']=7;
						$datas['uniacid']=$_W['uniacid'];
						$datas['number']=1;
						$datas['sjc']=time();
						$datas['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$datas);
					}
					pdo_update('zh_gjw_dbpublish', array('type' => $_GPC['alltype'],'pay' => 1,'upfee' =>1,'payfee'=>$allmoney), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//有发布费、有推荐、审核开启
				}else{
					if ($_GPC['alltype']==12) {
						pdo_update('zh_gjw_dbpublish', array('type' => 12,'pay' => 1,'upfee' =>1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=7;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==20) {
						pdo_update('zh_gjw_dbpublish', array('type' => 20,'pay' => 1,'upfee' =>1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=7;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					pdo_update('zh_gjw_dbpublish', array('type' => $_GPC['alltype'],'pay' => 1,'upfee' =>1,'payfee'=>$dbmoney['upfee']), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//无发布费、有推荐、审核开启
				}
			}
			if($_GPC['upstate']!=1){
				if ($dbmoney['publishfee']>0) {
					if ($_GPC['alltype']==17) {
						pdo_update('zh_gjw_dbpublish', array('type' => 17,'pay' => 1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=1;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==21) {
						pdo_update('zh_gjw_dbpublish', array('type' => 21,'pay' => 1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=1;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					pdo_update('zh_gjw_dbpublish', array('type' => $_GPC['alltype'],'pay' => 1,'payfee'=>$dbmoney['publishfee']), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//有发布费、无推荐、审核开启
				}else{
					pdo_update('zh_gjw_dbpublish', array('type' => $_GPC['alltype'],'pay' => 1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//无发布费、无推荐、审核开启
				}
			}
			echo json_encode(array('msg'=>'抖宝发布改变状态成功','code'=>'200','res'=>$res),320);exit();
		}elseif ($shset['dbshset']!=1) {
			if ($_GPC['upstate']==1) {
				if ($dbmoney['publishfee']>0) {
					$allmoney=$dbmoney['publishfee']+$dbmoney['upfee'];
					if ($_GPC['alltype']==14) {
						pdo_update('zh_gjw_dbpublish', array('type' => 14,'pay' => 1,'upfee' =>1,'payfee'=>$dbmoney['publishfee'],'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=1;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=7;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==18) {
						pdo_update('zh_gjw_dbpublish', array('type' => 18,'pay' => 1,'upfee' =>1,'payfee'=>$dbmoney['upfee'],'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=1;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==22) {
						pdo_update('zh_gjw_dbpublish', array('type' => 22,'pay' => 1,'upfee' =>1,'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=1;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
						$datas['openid']=$_GPC['openid'];
						$datas['type']=7;
						$datas['uniacid']=$_W['uniacid'];
						$datas['number']=1;
						$datas['sjc']=time();
						$datas['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$datas);
					}
					pdo_update('zh_gjw_dbpublish', array('type' => $_GPC['alltype'],'pay' => 1,'upfee' =>1,'payfee'=>$allmoney,'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//有发布费、有推荐、审核关闭
				}else{
					if ($_GPC['alltype']==12) {
						pdo_update('zh_gjw_dbpublish', array('type' => 12,'pay' => 1,'upfee' =>1,'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=7;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==20) {
						pdo_update('zh_gjw_dbpublish', array('type' => 20,'pay' => 1,'upfee' =>1,'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=7;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					pdo_update('zh_gjw_dbpublish', array('type' => $_GPC['alltype'],'pay' => 1,'upfee' =>1,'payfee'=>$dbmoney['upfee'],'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//无发布费、有推荐、审核关闭
				}
			}
			if($_GPC['upstate']!=1){
				if ($dbmoney['publishfee']>0) {
					if ($_GPC['alltype']==17) {
						pdo_update('zh_gjw_dbpublish', array('type' => 17,'pay' => 1,'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=1;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==21) {
						pdo_update('zh_gjw_dbpublish', array('type' => 21,'pay' => 1,'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=1;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					pdo_update('zh_gjw_dbpublish', array('type' => $_GPC['alltype'],'pay' => 1,'payfee'=>$dbmoney['publishfee'],'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//有发布费、无推荐、审核关闭
				}else{
					pdo_update('zh_gjw_dbpublish', array('type' => $_GPC['alltype'],'pay' => 1,'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//无发布费、无推荐、审核关闭
				}
			}
			set_msg($_W,$_GPC['res_id']);
			echo json_encode(array('msg'=>'抖宝发布改变状态成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'抖宝发布改变状态出错','code'=>'500','res'=>$res),320);exit();
	}
	//抖宝置顶
	public function doPageDbtoppay(){
		global $_GPC, $_W;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		$root=$_W['siteroot']; 
    	$primoney=pdo_get('zh_gjw_dbmoney',array('uniacid'=>$_W['uniacid']));
		$total_fee =$primoney['topfee'];
		if($total_fee>0)
		{
			$body = "抖宝置顶";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
		echo json_encode($return);
	}
	//抖宝置顶topfee+1
	public function doPageDbtopsuccess(){
		global $_W, $_GPC;
		file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=GetGradedbp&m=zh_gjw&order_id=" . $_GPC['id']);//修改等级
		$topfee=pdo_get('zh_gjw_dbpublish',array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		$topfee['topfee']=$topfee['topfee']+1;
		$res =	pdo_update('zh_gjw_dbpublish', array('topfee' =>$topfee['topfee'],'time'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if ($res) {
          	if($_GPC['openid']&&$_GPC['tops']==1){
				$datas['openid']=$_GPC['openid'];
				$datas['type']=8;
				$datas['uniacid']=$_W['uniacid'];
				$datas['number']=1;
				$datas['sjc']=time();
				$datas['time']=date('Y-m-d H:i:s',time());
				pdo_insert('zh_gjw_repucost',$datas);
			}else{
	          	$dbmoney=pdo_get('zh_gjw_dbmoney',array('uniacid'=>$_W['uniacid']));
				$data['p_id']=$_GPC['id'];
				$data['fee']=$dbmoney['topfee'];
				$data['uniacid']=$_W['uniacid'];
				$data['time']=date('Y-m-d H:i:s',time());
				if ($dbmoney['topfee']>0) {
					pdo_insert('zh_gjw_dborder',$data);
				}
			}
			echo json_encode(array('msg'=>'置顶成功','code'=>'200','res'=>$res),320);exit();
		}else{
			echo json_encode(array('msg'=>'置顶失败','code'=>'500'),320);exit();
		}
	}
	//抖宝推荐
	public function doPageDbuppay(){
		global $_GPC, $_W;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		$root=$_W['siteroot']; 
    	$primoney=pdo_get('zh_gjw_dbmoney',array('uniacid'=>$_W['uniacid']));
		$total_fee =$primoney['upfee'];
		if($total_fee>0)
		{
			$body = "抖宝推荐";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
		echo json_encode($return);
	}
	//抖宝推荐upfee+1
	public function doPageDbupsuccess(){
		global $_W, $_GPC;
      	
		file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=GetGradedbp&m=zh_gjw&order_id=" . $_GPC['id']);//修改等级
		$upfee=pdo_get('zh_gjw_dbpublish',array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		$res =	pdo_update('zh_gjw_dbpublish', array('upfee' =>1,'time'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if ($res) {
          	if($_GPC['openid']&&$_GPC['tuijian']==1){
				$datas['openid']=$_GPC['openid'];
				$datas['type']=7;
				$datas['uniacid']=$_W['uniacid'];
				$datas['number']=1;
				$datas['sjc']=time();
				$datas['time']=date('Y-m-d H:i:s',time());
				pdo_insert('zh_gjw_repucost',$datas);
			}else{
	          	$dbmoney=pdo_get('zh_gjw_dbmoney',array('uniacid'=>$_W['uniacid']));
				$data['p_id']=$_GPC['id'];
				$data['fee']=$dbmoney['upfee'];
				$data['uniacid']=$_W['uniacid'];
				$data['time']=date('Y-m-d H:i:s',time());
				if ($dbmoney['upfee']>0) {
					pdo_insert('zh_gjw_dborder',$data);
				}
			}
			echo json_encode(array('msg'=>'推荐成功','code'=>'200','res'=>$res),320);exit();
		}else{
			echo json_encode(array('msg'=>'推荐失败','code'=>'500'),320);exit();
		}
	}

	/**
	*抖宝浏览
	*/
	// public function doPageDbview(){
	// 	global $_GPC, $_W;
	// 	$id=pdo_get('zh_gjw_dbpublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
	// 	$view=$id['view']+1;
	// 	$res = pdo_update('zh_gjw_dbpublish', array('view' =>$view), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
	// 	if (empty($res)) {
	// 		echo json_encode(array('msg'=>'浏览失败','code'=>'500'),320);exit();
	// 	}
	// 	echo json_encode(array('msg'=>'浏览记录成功','code'=>'200'),320);exit();
	// }
	public function doPageDbview(){
		global $_GPC, $_W;
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$id=pdo_get('zh_gjw_dbpublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if (empty($id['view'])) {
			pdo_update('zh_gjw_dbpublish', array('view' =>$user['id']), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
			echo json_encode(array('msg'=>'浏览成功','code'=>'200','res'=>1),320);exit();
		}else{
			$ids=explode(",",$id['view']);
			if (in_array($user['id'], $ids)){
				if (in_array(0,$ids)) {
					$idss=count($ids)-1;
				}else{
					$idss=count($ids);
				}
				echo json_encode(array('msg'=>'浏览过了','code'=>'201','res'=>$idss),320);exit();
			}else{
				array_push($ids,$user['id']);
				$view=implode(',', $ids);
				$res = pdo_update('zh_gjw_dbpublish', array('view' =>$view), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
				if (empty($res)) {
					echo json_encode(array('msg'=>'浏览失败','code'=>'500'),320);exit();
				}
				$viewid=pdo_get('zh_gjw_dbpublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
				if (in_array(0,explode(",",$viewid['view']))) {
					$viewids=count(explode(",",$viewid['view']))-1;
				}else{
					$viewids=count(explode(",",$viewid['view']));
				}
				echo json_encode(array('msg'=>'浏览成功','code'=>'200','res'=>$viewids),320);exit();
			}
		}
	}

	/**
	*抖宝点赞
	*/
	public function doPageDbagree(){
		global $_GPC, $_W;
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$id=pdo_get('zh_gjw_dbpublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if (empty($id['agree'])) {
			pdo_update('zh_gjw_dbpublish', array('agree' =>$user['id']), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
			echo json_encode(array('msg'=>'点赞成功','code'=>'200','res'=>1),320);exit();
		}else{
			$ids=explode(",",$id['agree']);
			if (in_array($user['id'], $ids)){
				if (in_array(0,$ids)) {
					$idss=count($ids)-1;
				}else{
					$idss=count($ids);
				}
				echo json_encode(array('msg'=>'点赞过了','code'=>'201','res'=>$idss),320);exit();
			}else{
				array_push($ids,$user['id']);
				$agree=implode(',', $ids);
				$res = pdo_update('zh_gjw_dbpublish', array('agree' =>$agree), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
				if (empty($res)) {
					echo json_encode(array('msg'=>'点赞失败','code'=>'500'),320);exit();
				}
				$agreeid=pdo_get('zh_gjw_dbpublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
				if (in_array(0,explode(",",$agreeid['agree']))) {
					$agreeids=count(explode(",",$agreeid['agree']))-1;
				}else{
					$agreeids=count(explode(",",$agreeid['agree']));
				}
				echo json_encode(array('msg'=>'点赞成功','code'=>'200','res'=>$agreeids),320);exit();
			}
		}
	}
	/**
	*抖宝点赞
	*/
	// public function doPageDbagree(){
	// 	global $_GPC, $_W;
	// 	$id=pdo_get('zh_gjw_dbpublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
	// 	$agree=$id['agree']+1;
	// 	$res = pdo_update('zh_gjw_dbpublish', array('agree' =>$agree), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
	// 	if (empty($res)) {
	// 		echo json_encode(array('msg'=>'点赞失败','code'=>'500'),320);exit();
	// 	}
	// 	echo json_encode(array('msg'=>'点赞成功','code'=>'200'),320);exit();
	// }
	//抖宝分类数据
	public function doPageDbcateid(){
		global $_W, $_GPC;
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE uniacid=:uniacid and c_id=:c_id and state=:state ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':c_id']=$_GPC['c_id'];
		$data[':state']=2;
		$sql="SELECT * FROM ".tablename('zh_gjw_dbpublish').$where." ORDER BY time desc";
  		$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_dbpublish').$where." ORDER BY time desc",$data);
  		$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);

		// $res=pdo_getall('zh_gjw_dbpublish',array('c_id'=>$_GPC['c_id'],'uniacid'=>$_W['uniacid'],'state'=>2), array() , '' , 'time DESC' , array());

		// $res = pdo_fetchall("SELECT a.*,b.storeimg FROM ".tablename('zh_gjw_dbpublish'). " a left join " . tablename("zh_gjw_cusmanage") . " b on a.openid=b.openid WHERE a.uniacid=:uniacid and a.c_id=:c_id ORDER BY a.time desc", array(':uniacid'=>$_W['uniacid'],':c_id'=>$_GPC['c_id']));

		if (empty($res)) {
			echo json_encode(array('msg'=>'没有抖宝分类数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res) ; $i++) { 

				$resu=pdo_get('zh_gjw_cusmanage',array('openid'=>$res[$i]['openid']));
				if ($resu) {
    				$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
					$res[$i]['cusname']=$resu['cusname'];
					$res[$i]['level_name']=$resu['level_name'];
					$res[$i]['storeimg']=$resu['storeimg'];
					$res[$i]['reputation']=$resu['reputation'];
					$res[$i]['xybzj']=$totalmoney['total_money'];
				}else{
					$resu=pdo_get('zh_gjw_register',array('openid'=>$res[$i]['openid']));
					$res[$i]['level_name']=$resu['level_name'];
					$res[$i]['cusname']=$resu['cusname'];
				}

				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
			}
			echo json_encode(array('msg'=>'抖宝分类数据','code'=>'200','res'=>$res),320);exit();
		}
	}
	//抖宝推荐
	public function doPageDbupfee(){
		global $_W, $_GPC;

		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE uniacid=:uniacid and upfee=:upfee and state=:state ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':upfee']=1;
		$data[':state']=2;
		$sql="SELECT * FROM ".tablename('zh_gjw_dbpublish').$where." ORDER BY time desc";
  		$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_dbpublish').$where." ORDER BY time desc",$data);
  		$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);

		// $res=pdo_getall('zh_gjw_dbpublish',array('upfee'=>1,'uniacid'=>$_W['uniacid']), array() , '' , 'topfee DESC' , array());

		// $res = pdo_fetchall("SELECT a.*,b.storeimg FROM ".tablename('zh_gjw_dbpublish'). " a left join " . tablename("zh_gjw_cusmanage") . " b on a.openid=b.openid WHERE a.uniacid=:uniacid and a.upfee=:upfee ORDER BY a.time desc", array(':uniacid'=>$_W['uniacid'],':upfee'=>1));
		
		if (empty($res)) {
			echo json_encode(array('msg'=>'没有抖宝分类数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res) ; $i++) { 

				$resu=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone']));
				if ($resu) {
    				$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
					$res[$i]['cusname']=$resu['cusname'];
					$res[$i]['level_name']=$resu['level_name'];
					$res[$i]['storeimg']=$resu['storeimg'];
					$res[$i]['reputation']=$resu['reputation'];
					$res[$i]['xybzj']=$totalmoney['total_money'];
				}else{
					$resu=pdo_get('zh_gjw_register',array('openid'=>$res[$i]['openid']));
					$res[$i]['level_name']=$resu['level_name'];
					$res[$i]['cusname']=$resu['cusname'];
				}

				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
			}
			echo json_encode(array('msg'=>'抖宝推荐数据','code'=>'200','res'=>$res),320);exit();
		}
	}
	//抖宝详情点赞没有
	public function doPageDbagreedetail(){
		global $_W, $_GPC;
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$id=pdo_get('zh_gjw_dbpublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		// if (!empty($id)) {
			$ids=explode(",",$id['agree']);
			if (in_array($user['id'], $ids)){
					echo json_encode(array('msg'=>'点赞过了','code'=>'200'),320);exit();
			}else{
				echo json_encode(array('msg'=>'没有点赞过','code'=>'500'),320);exit();
			}
		// }
	}

	/**
	*抖宝全部/审
	*/
	public function doPageDball(){
		global $_GPC, $_W;
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE uniacid=:uniacid and pay=:pay and openid=:openid ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':pay']=1;
		$data[':openid']=$_GPC['openid'];
		$sql="SELECT * FROM ".tablename('zh_gjw_dbpublish').$where." ORDER BY time desc";
  		$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_dbpublish').$where." ORDER BY time desc",$data);
  		$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		// $shset=pdo_get('zh_gjw_shset',array('uniacid'=>$_W['uniacid']));
		// if ($shset['dbshset']==1) {
		// $res=pdo_getall('zh_gjw_dbpublish',array('uniacid'=>$_W['uniacid'],'pay'=>1,'openid'=>$_GPC['openid']));
		// }
		for ($i=0; $i <count($res) ; $i++) { 
				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
		}
		if (empty($res)) {
			echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
		}
			for ($i=0; $i <count($res) ; $i++) { 

				$resu=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['reputation']=$resu['reputation'];
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['level_name']=$resu['level_name'];
				$res[$i]['cusname']=$resu['cusname'];
				$res[$i]['storeimg']=$resu['storeimg'];

				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
			}
		echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res),320);exit();
	}

	/**
	*抖宝/未审核
	*/
	public function doPageDbnsh(){
		global $_GPC, $_W;
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE uniacid=:uniacid and pay=:pay and openid=:openid and state=:state ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':pay']=1;
		$data[':state']=1;
		$data[':openid']=$_GPC['openid'];
		$sql="SELECT * FROM ".tablename('zh_gjw_dbpublish').$where." ORDER BY time desc";
  		$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_dbpublish').$where." ORDER BY time desc",$data);
  		$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		// $shset=pdo_get('zh_gjw_shset',array('uniacid'=>$_W['uniacid']));
		// if ($shset['dbshset']==1) {
			// $res=pdo_getall('zh_gjw_dbpublish',array('state'=>1,'pay'=>1,'uniacid'=>$_W['uniacid'],'openid'=>$_GPC['openid']));
			// $res = pdo_fetchall("SELECT a.*,b.openid,b.phone FROM " . tablename('zh_gjw_dbpublish'). " a"  . " left join " . tablename("zh_gjw_register") . " b on a.phone=b.phone WHERE a.uniacid=:uniacid and b.openid=:openid and a.state=:state ORDER BY a.time desc", array(':uniacid'=>$_W['uniacid'],':openid'=>$_GPC['openid'],':state'=>1));
		// }

		for ($i=0; $i <count($res) ; $i++) { 
				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
		}
		if (empty($res)) {
			echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
		}
		echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res),320);exit();
	}
	/**
	*抖宝/已审核
	*/
	public function doPageDbysh(){
		global $_GPC, $_W;
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE uniacid=:uniacid and pay=:pay and openid=:openid and state=:state ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':pay']=1;
		$data[':state']=2;
		$data[':openid']=$_GPC['openid'];
		$sql="SELECT * FROM ".tablename('zh_gjw_dbpublish').$where." ORDER BY time desc";
  		$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_dbpublish').$where." ORDER BY time desc",$data);
  		$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		// $shset=pdo_get('zh_gjw_shset',array('uniacid'=>$_W['uniacid']));
		// if ($shset['dbshset']==1) {
			// $res=pdo_getall('zh_gjw_dbpublish',array('state'=>2,'pay'=>1,'uniacid'=>$_W['uniacid'],'openid'=>$_GPC['openid']));
		// }

		for ($i=0; $i <count($res) ; $i++) { 
				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
		}
		if (empty($res)) {
			echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
		}
			for ($i=0; $i <count($res) ; $i++) { 

				$resu=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['reputation']=$resu['reputation'];
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['level_name']=$resu['level_name'];
				$res[$i]['cusname']=$resu['cusname'];
				$res[$i]['storeimg']=$resu['storeimg'];

				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
			}
		echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res),320);exit();
	}
	/**
	*抖宝/已拒审核
	*/
	public function doPageDbjsh(){
		global $_GPC, $_W;
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE uniacid=:uniacid and pay=:pay and openid=:openid and state=:state ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':pay']=1;
		$data[':state']=3;
		$data[':openid']=$_GPC['openid'];
		$sql="SELECT * FROM ".tablename('zh_gjw_dbpublish').$where." ORDER BY time desc";
  		$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_dbpublish').$where." ORDER BY time desc",$data);
  		$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		// $shset=pdo_get('zh_gjw_shset',array('uniacid'=>$_W['uniacid']));
		// if ($shset['dbshset']==1) {
			// $res=pdo_getall('zh_gjw_dbpublish',array('state'=>3,'pay'=>1,'uniacid'=>$_W['uniacid'],'openid'=>$_GPC['openid']));
		// }

		for ($i=0; $i <count($res) ; $i++) { 
				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
		}
		if (empty($res)) {
			echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
		}
		echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res),320);exit();
	}

	/**
	*抖宝评论
	*/
	public function doPageDbassess(){
		global $_GPC, $_W;
		$shset=pdo_get('zh_gjw_shset',array('uniacid'=>$_W['uniacid']));
		$openid_id=pdo_get('zh_gjw_register',array('uniacid'=>$_W['uniacid'],'openid'=>$_GPC['openid']));
		$data['content']=$_GPC['content'];
		$data['u_id']=$openid_id['id'];
		$data['p_id']=$_GPC['p_id'];
		$data['formid']=$_GPC['formid'];
		if($shset['dbassessshset']==1){
			$data['state']=1;
		}else{
			$data['state']=2;
		}
		$data['uniacid']=$_W['uniacid'];
		$data['time']=date('Y-m-d H:i:s',time());
		$res=pdo_insert('zh_gjw_dbassess',$data);
		$res_id=pdo_insertid();
		if (empty($res)) {
			echo json_encode(array('msg'=>'评论失败','code'=>'500'),320);exit();
		}
		/*function getaccess_token($_W){
          $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
          $appid=$res['appid'];
          $secret=$res['appsecret'];
          $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL,$url);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
          $data = curl_exec($ch);
          curl_close($ch);
          $data = json_decode($data,true);
          return $data['access_token'];
        }*/
        function set_msg($_W,$res_id){
            //$access_token = getaccess_token($_W);
            $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
            $user=pdo_get('zh_gjw_dbassess',array('id'=>$res_id));
            $content=mb_substr($user['content'],0,3,'utf-8');
            $openid=pdo_get('zh_gjw_register',array('id'=>$user['u_id']));
            $formwork ='{
                "touser": "'.$openid["openid"].'",
                "template_id": "'.$ress["templeid"].'",
                "form_id":"'.$user['formid'].'",
                "data": {
                    "keyword1": {
                        "value": "'.$content.'...",
                        "color": "#173177"
                    },
                    "keyword2": {
                        "value":"抖宝评论审核通过",
                        "color": "#173177"
                    }
                }  
            }';
            $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL,$url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
            curl_setopt($ch, CURLOPT_POST,1);
            curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
            $data = curl_exec($ch);
            curl_close($ch);
           return $data;
        }
        if($shset['dbassessshset']!=1){
			set_msg($_W,$res_id);
		}
		echo json_encode(array('msg'=>'评论成功','code'=>'200'),320);exit();
	}

	/**
	*获取抖宝评论
	*/
	public function doPageDbassessget(){
		global $_GPC, $_W;
		
			// $res=pdo_fetchall("SELECT a.*,b.avatar,b.username FROM " . tablename('zh_gjw_dbassess'). " a"  . " left join " . tablename("zh_gjw_register") . " b on a.u_id=b.id WHERE  a.p_id=:p_id and a.uniacid=:uniacid and a.state=:state", array(':p_id'=>$_GPC['p_id'],':uniacid'=>$_W['uniacid'],':state'=>2));

		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=10;
		$where=' WHERE a.uniacid=:uniacid and a.p_id=:p_id and a.state=:state ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':p_id']=$_GPC['p_id'];
		$data[':state']=2;
		$sql="SELECT a.*,b.avatar,b.username FROM ".tablename('zh_gjw_dbassess'). " a left join " . tablename("zh_gjw_register") . " b on a.u_id=b.id" .$where." ORDER BY a.time desc";
  		$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_dbassess'). " a left join " . tablename("zh_gjw_register") . " b on a.u_id=b.id" .$where." ORDER BY a.time desc",$data);
  		$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);

		if (empty($res)) {
			echo json_encode(array('msg'=>'获取失败','code'=>'500'),320);exit();
		}
		echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res),320);exit();
	}
	//生成抖宝订单
	public function doPageDborder(){
		global $_W,$_GPC;
		$cus_id=pdo_get('zh_gjw_dbpublish',array('id'=>$_GPC['p_id']));
		$cusm=pdo_get('zh_gjw_cusmanage',array('phone'=>$cus_id['phone']));
		$u_id=pdo_get('zh_gjw_register',array('uniacid'=>$_W['uniacid'],'openid'=>$_GPC['openid']));
		$data['u_id']=$u_id['id'];
		$data['formid']=$_GPC['formid'];
		$data['cus_id']=$cusm['id'];
		$data['p_id']=$_GPC['p_id'];
		$data['type']=$_GPC['type'];
		$data['ordernum']=date('Ymdhis').$u_id['id'].rand(10,99);
		$data['ofee']=$_GPC['ofee'];
		$data['message']=$_GPC['message'];
		$data['phone']=$_GPC['phone'];
		$data['uname']=$_GPC['name'];
		$data['state']=1;
		$data['address']=$_GPC['address'];
		$data['num']=$_GPC['num'];
		$data['ofees']=$_GPC['ofees'];
		$data['uniacid']=$_W['uniacid'];
		$data['time']=date('Y-m-d H:i:s',time());
		$data['timesjc']=time();
		$res=pdo_insert('zh_gjw_orders',$data);
		$res_id=pdo_insertid();
		if (empty($res)) {
			echo json_encode(array('msg'=>'提交失败','code'=>'500'),320);exit();
		}
		echo json_encode(array('msg'=>'提交成功','code'=>'200','res_id'=>$res_id),320);exit();

	}
	//抖宝订单支付
	public function doPageDborderpay(){
		global $_W,$_GPC;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		pdo_update('zh_gjw_orders', array('paycode' =>$out_trade_no), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		$root=$_W['siteroot']; 
		$total_fee =$_GPC['ofees'];
		if($total_fee>0)
		{
			$body = "抖宝订单支付";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
		echo json_encode($return);
	}

	//抖宝订单支付成功改变state
	public function doPageDborderpaysuccess(){
		global $_W, $_GPC;
		/*function getaccess_token($_W){
          $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
          $appid=$res['appid'];
          $secret=$res['appsecret'];
          $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL,$url);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
          $data = curl_exec($ch);
          curl_close($ch);
          $data = json_decode($data,true);
          return $data['access_token'];
        }
        function set_msg($_W,$res){
            //$access_token = getaccess_token($_W);
            $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
            $user=pdo_get('zh_gjw_register',array('id'=>$res['u_id']));
            $orders=pdo_get('zh_gjw_orders',array('id'=>$res['id']));
            $dbname=pdo_get('zh_gjw_dbpublish',array('id'=>$res['p_id']));
            $formwork ='{
                "touser": "'.$user["openid"].'",
                "template_id": "'.$ress["templeidos"].'",
                "form_id":"'.$orders['formid'].'",
                "data": {
                    "keyword1": {
                        "value": "'.$orders['time'].'",
                        "color": "#173177"
                    },
                    "keyword2": {
                        "value":"'.$orders['paytime'].'",
                        "color": "#173177"
                    },
                    "keyword3": {
                        "value":"'.$dbname['dbname'].'",
                        "color": "#173177"
                    },
                    "keyword4": {
                        "value":"'.$orders['ordernum'].'",
                        "color": "#173177"
                    },
                    "keyword5": {
                        "value":"'.$orders['ofees'].'",
                        "color": "#173177"
                    },
                    "keyword6": {
                        "value":"'.$orders['id'].'",
                        "color": "#173177"
                    },
                    "keyword7": {
                        "value":"抖宝购买成功",
                        "color": "#173177"
                    }
                }  
            }';
            $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL,$url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
            curl_setopt($ch, CURLOPT_POST,1);
            curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
            $data = curl_exec($ch);
            curl_close($ch);
           return $data;
        }*/
		$res = pdo_update('zh_gjw_orders', array('state' =>2,'paytime' =>date('Y-m-d H:i:s')), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		if ($res) {
            /*$orderid=pdo_get('zh_gjw_orders',array('id'=>$_GPC['res_id']));
			set_msg($_W,$orderid);*/
                file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=GetGrade&m=zh_gjw&order_id=" . $_GPC['res_id']);//修改等级
			echo json_encode(array('msg'=>'成功','code'=>'200'),320);exit();
		}
		echo json_encode(array('msg'=>'失败','code'=>'500'),320);exit();
	}
	//抖宝店铺名称
    public function doPageDbcusname(){
    	global $_GPC,$_W;
    	$openid=pdo_get('dbpublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
    	$cusname=pdo_get('zh_gjw_cusmanage',array('openid'=>$cusname['openid'],'uniacid'=>$_W['uniacid']));
    	if (empty($cusname)) {
    		$user=pdo_get('zh_gjw_register',array('openid'=>$cusname['openid'],'uniacid'=>$_W['uniacid']));
    		if (empty($user)) {
    			echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
    		}else{
    			echo json_encode(array('msg'=>'查询用户信息成功','code'=>'201','res'=>$cusname),320);exit();
    		}
    	}elseif($cusname){
    		echo json_encode(array('msg'=>'查询商家店铺成功','code'=>'200','res'=>$cusname),320);exit();
    	}
    	echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
    }
    //抖宝删除
    public function doPageDbdelete(){
    	global $_GPC,$_W;
    	$res=pdo_delete('zh_gjw_dbpublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if ($res) {
		echo json_encode(array('msg'=>'删除成功','code'=>'200'),320);exit();
		}
		echo json_encode(array('msg'=>'删除失败','code'=>'500'),320);exit();

    }
    //微拍费
    public function doPageShotmoney(){
    	global $_GPC,$_W;
    	$shotmoney=pdo_get('zh_gjw_shotmoney',array('uniacid'=>$_W['uniacid']));
    	if (empty($shotmoney)) {
    		echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
    	}elseif($shotmoney){
    		echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$shotmoney),320);exit();
    	}
    }
    //发布微拍
    public function doPageShotpublish(){
    	global $_GPC,$_W;
		$data['formid']=$_GPC['formid'];
		$data['title']=$_GPC['title'];
		$data['phone']=$_GPC['admin'];
		$data['shotmoney']=$_GPC['shotmoney'];
		$data['userbzj']=$_GPC['userbzj'];
		$data['bzj']=$_GPC['bzj'];
		$data['ckmoney']=$_GPC['ckmoney'];
		$data['addmoney']=$_GPC['addmoney'];
		$data['co_id']=$_GPC['co_id'];
		$data['ct_id']=$_GPC['ct_id'];
		$data['cth_id']=$_GPC['cth_id'];
		$data['fromtime']=$_GPC['fromtime'];
		$data['totime']=$_GPC['totime'];
		$data['exfee']=$_GPC['exfee'];
		$data['detail']=$_GPC['detail'];
		$data['img']=$_GPC['img'];
		$data['video']=$_GPC['videoimgtemp'];
		$data['videoimg']=$_GPC['shotvideoimg'];
		$data['state']=1;
		$data['uniacid']=$_W['uniacid'];
		$data['time']=date('Y-m-d H:i:s',time());
		$res=pdo_insert('zh_gjw_shotpublish',$data);
		$res_id=pdo_insertid();
    	if ($res) {
    		echo json_encode(array('msg'=>'记录成功','code'=>'200','res'=>$res,'res_id'=>$res_id),320);exit();
		}else{
			echo json_encode(array('msg'=>'记录失败','code'=>'500'),320);exit();
		}
    }
    //微拍支付
	public function doPageShotpay(){
		global $_W, $_GPC;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$res_fee=0;
    	$shset=pdo_get('zh_gjw_shset',array('uniacid'=>$_W['uniacid']));
    	if ($shset['shotshset']==1) {
	    	if ($_GPC['upstate']==1) {
	    		if($_GPC['publishfee']>0){
	    			$res_fee=$_GPC['publishfee']+$_GPC['bzj']+$_GPC['upfee'];
	    		}else{
	    			$res_fee=$_GPC['bzj']+$_GPC['upfee'];
	    		}
			}else{
				if($_GPC['publishfee']>0){
	    			$res_fee=$_GPC['publishfee']+$_GPC['bzj'];
	    		}else{
	    			$res_fee=$_GPC['bzj'];
	    		}
			}
    	}elseif ($shset['shotshset']!=1) {
    		if ($_GPC['upstate']==1) {
	    		if($_GPC['publishfee']>0){
	    			$res_fee=$_GPC['publishfee']+$_GPC['bzj']+$_GPC['upfee'];
	    		}else{
	    			$res_fee=$_GPC['bzj']+$_GPC['upfee'];
	    		}
			}else{
				if($_GPC['publishfee']>0){
	    			$res_fee=$_GPC['publishfee']+$_GPC['bzj'];
	    		}else{
	    			$res_fee=$_GPC['bzj'];
	    		}
			}
    	}
		
		if ($_GPC['alltype']==20) {
    		$res_fee=$res_fee-$_GPC['upfee'];
    	}
		if ($_GPC['alltype']==23) {
    		$res_fee=$res_fee-$_GPC['upfee'];
    	}
		if ($_GPC['alltype']==24) {
    		$res_fee=$res_fee-$_GPC['upfee'];
    	}
		if ($_GPC['alltype']==30) {
    		$res_fee=$res_fee-$_GPC['publishfee'];
    	}
		if ($_GPC['alltype']==31) {
    		$res_fee=$res_fee-$_GPC['publishfee'];
    	}
		if ($_GPC['alltype']==32) {
    		$res_fee=$res_fee-$_GPC['publishfee'];
    	}
		if ($_GPC['alltype']==36) {
    		$res_fee=$res_fee-$_GPC['upfee'];
    	}
		if ($_GPC['alltype']==38) {
    		$res_fee=$res_fee-$_GPC['publishfee'];
    	}
		if ($_GPC['alltype']==40) {
    		$res_fee=$res_fee-$_GPC['publishfee']-$_GPC['upfee'];
    	}
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		pdo_update('zh_gjw_shotpublish', array('paycode' =>$out_trade_no), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		$root=$_W['siteroot']; 
		$total_fee =$res_fee;
		if($total_fee>0)
		{
			$body = "微拍发布";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
		echo json_encode($return);
	}
	//微拍支付成功改变state
	public function doPageShotsuccess(){
		global $_W, $_GPC;
      
		file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=GetGradeshotp&m=zh_gjw&order_id=" . $_GPC['res_id']);//修改等级
		/*function getaccess_token($_W){
          $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
          $appid=$res['appid'];
          $secret=$res['appsecret'];
          $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL,$url);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
          $data = curl_exec($ch);
          curl_close($ch);
          $data = json_decode($data,true);
          return $data['access_token'];
        }*/
        function set_msg($_W,$id){
            //$access_token = getaccess_token($_W);
            $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
            $openid=pdo_get('zh_gjw_shotpublish',array('id'=>$id));
            $register=pdo_get('zh_gjw_register',array('phone'=>$openid['phone']));
            $formwork ='{
                "touser": "'.$register["openid"].'",
                "template_id": "'.$ress["templeid"].'",
                "form_id":"'.$openid['formid'].'",
                "data": {
                    "keyword1": {
                        "value": "'.$openid['title'].'",
                        "color": "#173177"
                    },
                    "keyword2": {
                        "value":"微拍审核通过",
                        "color": "#173177"
                    }
                }  
            }';
            $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL,$url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
            curl_setopt($ch, CURLOPT_POST,1);
            curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
            $data = curl_exec($ch);
            curl_close($ch);
           return $data;
        }
    	$shset=pdo_get('zh_gjw_shset',array('uniacid'=>$_W['uniacid']));
    	$shotmoney=pdo_get('zh_gjw_shotmoney',array('uniacid'=>$_W['uniacid']));
    	$shotpublish=pdo_get('zh_gjw_shotpublish',array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
    	if ($shset['shotshset']==1) {
			if ($_GPC['upstate']==1) {
				if ($shotmoney['publishfee']>0) {
					$allmoney=$shotmoney['publishfee']+$shotmoney['upfee']+$shotpublish['bzj'];
                  	if ($_GPC['alltype']==23) {
						pdo_update('zh_gjw_shotpublish', array('type' => 23,'pay' => 1,'upfee' =>1,'payfee'=>$shotmoney['publishfee']), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=9;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==24) {
						$bzjfb=$shotmoney['publishfee']+$shotpublish['bzj'];
						pdo_update('zh_gjw_shotpublish', array('type' => 24,'pay' => 1,'upfee' =>1,'payfee'=>$bzjfb), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=9;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==31) {
						pdo_update('zh_gjw_shotpublish', array('type' => 31,'pay' => 1,'upfee' =>1,'payfee'=>$shotmoney['upfee']), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=2;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==32) {
						$bzjup=$shotmoney['upfee']+$shotpublish['bzj'];
						pdo_update('zh_gjw_shotpublish', array('type' => 32,'pay' => 1,'upfee' =>1,'payfee'=>$bzjup), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=2;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==39) {
						pdo_update('zh_gjw_dbpublish', array('type' => 39,'pay' => 1,'upfee' =>1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=2;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
						$datas['openid']=$_GPC['openid'];
						$datas['type']=9;
						$datas['uniacid']=$_W['uniacid'];
						$datas['number']=1;
						$datas['sjc']=time();
						$datas['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$datas);
					}
					if ($_GPC['alltype']==40) {
						pdo_update('zh_gjw_dbpublish', array('type' => 40,'pay' => 1,'upfee' =>1,'payfee'=>$shotpublish['bzj']), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=2;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
						$datas['openid']=$_GPC['openid'];
						$datas['type']=9;
						$datas['uniacid']=$_W['uniacid'];
						$datas['number']=1;
						$datas['sjc']=time();
						$datas['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$datas);
					}
					pdo_update('zh_gjw_shotpublish', array('type' => $_GPC['alltype'],'pay' => 1,'upfee' =>1,'payfee'=>$allmoney,'uptime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//有发布费、有推荐、审核开启
				}else{
					$allmoney=$shotmoney['upfee']+$shotpublish['bzj'];
                  	if ($_GPC['alltype']==19) {
						pdo_update('zh_gjw_shotpublish', array('type' => 19,'pay' => 1,'upfee' =>1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=9;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==20) {
						pdo_update('zh_gjw_shotpublish', array('type' => 20,'pay' => 1,'upfee' =>1,'payfee'=>$shotpublish['bzj']), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=9;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==35) {
						pdo_update('zh_gjw_shotpublish', array('type' => 35,'pay' => 1,'upfee' =>1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=9;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==36) {
						pdo_update('zh_gjw_shotpublish', array('type' => 36,'pay' => 1,'upfee' =>1,'payfee'=>$shotpublish['bzj']), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=9;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					pdo_update('zh_gjw_shotpublish', array('type' => $_GPC['alltype'],'pay' => 1,'upfee' =>1,'payfee'=>$allmoney,'uptime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//无发布费、有推荐、审核开启
				}
			}
			if($_GPC['upstate']!=1){
				if ($shotmoney['publishfee']>0) {
					$allmoney=$shotmoney['publishfee']+$shotpublish['bzj'];
                  	
                  	if ($_GPC['alltype']==29) {
						pdo_update('zh_gjw_shotpublish', array('type' => 29,'pay' => 1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=2;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==30) {
						pdo_update('zh_gjw_shotpublish', array('type' => 30,'pay' => 1,'payfee'=>$shotpublish['bzj']), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=2;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==37) {
						pdo_update('zh_gjw_shotpublish', array('type' => 37,'pay' => 1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=2;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==38) {
						pdo_update('zh_gjw_shotpublish', array('type' => 38,'pay' => 1,'payfee'=>$shotpublish['bzj']), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=2;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					pdo_update('zh_gjw_shotpublish', array('type' => $_GPC['alltype'],'pay' => 1,'payfee'=>$allmoney), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//有发布费、无推荐、审核开启
				}else{
					pdo_update('zh_gjw_shotpublish', array('type' => $_GPC['alltype'],'pay' => 1,'payfee'=>$shotpublish['bzj']), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//无发布费、无推荐、审核开启
				}
			}
			echo json_encode(array('msg'=>'微拍发布改变状态成功','code'=>'200','res'=>$res),320);exit();
		}elseif ($shset['shotshset']!=1) {
			if ($_GPC['upstate']==1) {
				if ($shotmoney['publishfee']>0) {
					$allmoney=$shotmoney['publishfee']+$shotmoney['upfee']+$shotpublish['bzj'];
                  	if ($_GPC['alltype']==23) {
						pdo_update('zh_gjw_shotpublish', array('type' => 23,'pay' => 1,'upfee' =>1,'payfee'=>$shotmoney['publishfee'],'state' => 2,'shtime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=9;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==24) {
						$bzjfb=$shotmoney['publishfee']+$shotpublish['bzj'];
						pdo_update('zh_gjw_shotpublish', array('type' => 24,'pay' => 1,'upfee' =>1,'payfee'=>$bzjfb,'state' => 2,'shtime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=9;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==31) {
						pdo_update('zh_gjw_shotpublish', array('type' => 31,'pay' => 1,'upfee' =>1,'payfee'=>$shotmoney['upfee'],'state' => 2,'shtime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=2;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==32) {
						$bzjup=$shotmoney['upfee']+$shotpublish['bzj'];
						pdo_update('zh_gjw_shotpublish', array('type' => 32,'pay' => 1,'upfee' =>1,'payfee'=>$bzjup,'state' => 2,'shtime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=2;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==39) {
						pdo_update('zh_gjw_dbpublish', array('type' => 39,'pay' => 1,'upfee' =>1,'state' => 2,'shtime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=2;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
						$datas['openid']=$_GPC['openid'];
						$datas['type']=9;
						$datas['uniacid']=$_W['uniacid'];
						$datas['number']=1;
						$datas['sjc']=time();
						$datas['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$datas);
					}
					if ($_GPC['alltype']==40) {
						pdo_update('zh_gjw_dbpublish', array('type' => 40,'pay' => 1,'upfee' =>1,'payfee'=>$shotpublish['bzj'],'state' => 2,'shtime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=2;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
						$datas['openid']=$_GPC['openid'];
						$datas['type']=9;
						$datas['uniacid']=$_W['uniacid'];
						$datas['number']=1;
						$datas['sjc']=time();
						$datas['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$datas);
					}
					pdo_update('zh_gjw_shotpublish', array('type' => $_GPC['alltype'],'pay' => 1,'upfee' =>1,'payfee'=>$allmoney,'state' => 2,'uptime'=>date('Y-m-d H:i:s',time()),'shtime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//有发布费、有推荐、审核关闭
				}else{
					$allmoney=$shotmoney['upfee']+$shotpublish['bzj'];
                  	if ($_GPC['alltype']==19) {
						pdo_update('zh_gjw_shotpublish', array('type' => 19,'pay' => 1,'upfee' =>1,'state' => 2,'shtime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=9;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==20) {
						pdo_update('zh_gjw_shotpublish', array('type' => 20,'pay' => 1,'upfee' =>1,'payfee'=>$shotpublish['bzj'],'state' => 2,'shtime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=9;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==35) {
						pdo_update('zh_gjw_shotpublish', array('type' => 35,'pay' => 1,'upfee' =>1,'state' => 2,'shtime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=9;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==36) {
						pdo_update('zh_gjw_shotpublish', array('type' => 36,'pay' => 1,'upfee' =>1,'payfee'=>$shotpublish['bzj'],'state' => 2,'shtime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=9;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					pdo_update('zh_gjw_shotpublish', array('type' => $_GPC['alltype'],'pay' => 1,'upfee' =>1,'payfee'=>$allmoney,'state' => 2,'uptime'=>date('Y-m-d H:i:s',time()),'shtime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//无发布费、有推荐、审核关闭
				}
			}
			if($_GPC['upstate']!=1){
				if ($shotmoney['publishfee']>0) {
					$allmoney=$shotmoney['publishfee']+$shotpublish['bzj'];
                  	if ($_GPC['alltype']==29) {
						pdo_update('zh_gjw_shotpublish', array('type' => 29,'pay' => 1,'state' => 2,'shtime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=2;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==30) {
						pdo_update('zh_gjw_shotpublish', array('type' => 30,'pay' => 1,'payfee'=>$shotpublish['bzj'],'state' => 2,'shtime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=2;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==37) {
						pdo_update('zh_gjw_shotpublish', array('type' => 37,'pay' => 1,'state' => 2,'shtime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=2;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==38) {
						pdo_update('zh_gjw_shotpublish', array('type' => 38,'pay' => 1,'payfee'=>$shotpublish['bzj'],'state' => 2,'shtime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=2;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					pdo_update('zh_gjw_shotpublish', array('type' => $_GPC['alltype'],'pay' => 1,'payfee'=>$allmoney,'state' => 2,'shtime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//有发布费、无推荐、审核关闭
				}else{
					pdo_update('zh_gjw_shotpublish', array('type' => $_GPC['alltype'],'pay' => 1,'state' => 2,'payfee'=>$shotpublish['bzj'],'shtime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//无发布费、无推荐、审核关闭
				}
			}
			set_msg($_W,$_GPC['res_id']);
			echo json_encode(array('msg'=>'微拍发布改变状态成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'微拍发布改变状态出错','code'=>'500','res'=>$res),320);exit();
  		//$shset=pdo_get('zh_gjw_shset',array('uniacid'=>$_W['uniacid']));
		// if ($_GPC['upstate']==1) {
		// 	pdo_update('zh_gjw_shotpublish', array('upfee' => 1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		// }
		// if ($_GPC['topstate']==1) {
		// 	pdo_update('zh_gjw_shotpublish', array('topfee' => 1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		// }
		// if ($shset['shotshset']==1) {
		// 	$res = pdo_update('zh_gjw_shotpublish', array('pay' => 1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		// 	echo json_encode(array('msg'=>'嗨','code'=>'200','res'=>$res),320);exit();
		// }elseif ($shset['shotshset']==0||$shset['shotshset']==null) {
		// 	$res = pdo_update('zh_gjw_shotpublish', array('pay' => 1,'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		// 	echo json_encode(array('msg'=>'嗨','code'=>'200','res'=>$res),320);exit();
		// }
	}
	//微拍中全部数据
	public function doPageShotcateid(){
		global $_W, $_GPC;
		// $arr=array();
		// $res=pdo_fetchall("SELECT * FROM " . tablename('zh_gjw_shotpublish')."WHERE state=2 and uniacid=".$_W['uniacid']." and c_id=".$_GPC['c_id']);

		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE  uniacid=:uniacid and state=:state ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':state']=2;
	    //$data[':c_id']=$_GPC['c_id'];
      
	    $where.=" and shtime+INTERVAL 72 HOUR>NOW() and shtime+INTERVAL 24 HOUR<NOW() ";
	    //$where.=" and time+INTERVAL 96 HOUR>NOW() and time+INTERVAL 48 HOUR<NOW() ";
	    //$where.=" and totime >=FROM_UNIXTIME(".time().") and fromtime<=FROM_UNIXTIME(".time().")";
	    $sql="SELECT * FROM ".tablename('zh_gjw_shotpublish') .$where." ORDER BY time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_shotpublish').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);

		if (empty($res)) {
			echo json_encode(array('msg'=>'没有微拍分类数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res) ; $i++) { 
				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$ures[$i]=pdo_get('zh_gjw_register',array('phone'=>$res[$i]['phone']));
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['ulevel_name']=$ures[$i]['level_name'];
				$res[$i]['username']=$ures[$i]['username'];
				$resu=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['cusname']=$resu['cusname'];
				$res[$i]['level_name']=$resu['level_name'];
				$res[$i]['storeimg']=$resu['storeimg'];
				$res[$i]['reputation']=$resu['reputation'];
				$res[$i]['xybzj']=$totalmoney['total_money'];

				$shot=pdo_getall('zh_gjw_shotbuy',array('shot_id'=>$res[$i]['id'],'uniacid'=>$_W['uniacid']), array() , '' , 'fee DESC' , array());
				if ($shot) {
					$res[$i]['newfee']=$shot[0]['fee'];
				}else{
					$res[$i]['newfee']=0;
				}
				//$res[$i]['totimesjc']=strtotime($res[$i]['totime']);
				$res[$i]['totimesjc']=strtotime($res[$i]['shtime'])+86400*3;
				//$res[$i]['totimesjc']=strtotime($res[$i]['time'])+86400*4;
			}

			// for ($j=0; $j <count($res) ; $j++) { 
			// 	if (strtotime($res[$j]['totime'])>time() && time()>strtotime($res[$j]['fromtime'])) {
			// 		$res[$j]['totimesjc']=strtotime($res[$j]['totime']);
			// 		array_push($arr,$res[$j]);
			// 	}
			// }
			if (empty($res)) {
				echo json_encode(array('msg'=>'微拍分类数据','code'=>'500'),320);exit();
			}
			echo json_encode(array('msg'=>'微拍分类数据','code'=>'200','res'=>$res),320);exit();
		}
	}

	//微拍中推荐
	public function doPageShotupfee(){
		global $_W, $_GPC;
		// $arr=array();

		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE  uniacid=:uniacid and state=:state and upfee=:upfee ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':state']=2;
	    $data[':upfee']=1;
	    //$where.=" and totime >=FROM_UNIXTIME(".time().") and fromtime<=FROM_UNIXTIME(".time().")";
      	$where.=" and shtime+INTERVAL 72 HOUR>NOW() and shtime+INTERVAL 24 HOUR<NOW() ";
	    //$where.=" and time+INTERVAL 96 HOUR>NOW() and time+INTERVAL 48 HOUR<NOW() ";
	    $sql="SELECT * FROM ".tablename('zh_gjw_shotpublish') .$where." ORDER BY uptime desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_shotpublish').$where." ORDER BY uptime desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);

		// $res=pdo_fetchall("SELECT * FROM " . tablename('zh_gjw_shotpublish')."WHERE state=2 and upfee=1 and uniacid=".$_W['uniacid']);
		
		if (empty($res)) {
			echo json_encode(array('msg'=>'没有微拍推荐数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res); $i++) { 
				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}


				$ures[$i]=pdo_get('zh_gjw_register',array('phone'=>$res[$i]['phone']));
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['ulevel_name']=$ures[$i]['level_name'];
				$res[$i]['username']=$ures[$i]['username'];
				$resu=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['cusname']=$resu['cusname'];
				$res[$i]['level_name']=$resu['level_name'];
				$res[$i]['storeimg']=$resu['storeimg'];
				$res[$i]['reputation']=$resu['reputation'];
				$res[$i]['xybzj']=$totalmoney['total_money'];


				$shot=pdo_getall('zh_gjw_shotbuy',array('shot_id'=>$res[$i]['id'],'uniacid'=>$_W['uniacid']), array() , '' , 'fee DESC' , array());
				if ($shot) {
					$res[$i]['newfee']=$shot[0]['fee'];
				}else{
					$res[$i]['newfee']=0;
				}
				$res[$i]['totimesjc']=strtotime($res[$i]['shtime'])+86400*3;
				//$res[$i]['totimesjc']=strtotime($res[$i]['time'])+86400*4;

			}

			// for ($j=0; $j <count($res) ; $j++) { 
			// 	if (strtotime($res[$j]['totime'])>time() && time()>strtotime($res[$j]['fromtime'])) {
			// 		$res[$j]['totimesjc']=strtotime($res[$j]['totime']);
			// 		array_push($arr,$res[$j]);
			// 	}
			// }
			if (empty($res)) {
				echo json_encode(array('msg'=>'微拍推荐数据','code'=>'500'),320);exit();
			}
			echo json_encode(array('msg'=>'微拍推荐数据','code'=>'200','res'=>$res),320);exit();
		}
	}
	//微拍预展中分类数据
	public function doPageShotwillcateid(){
		global $_W, $_GPC;
		
		// $arr=array();
		// $res=pdo_fetchall("SELECT * FROM " . tablename('zh_gjw_shotpublish')."WHERE state=2 and uniacid=".$_W['uniacid']." and c_id=".$_GPC['c_id']);


		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE  uniacid=:uniacid and state=:state and co_id=:co_id ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':state']=2;
	    $data[':co_id']=$_GPC['co_id'];
	    //$where.=" and NOW()<fromtime and fromtime<NOW()+INTERVAL 48 HOUR";
	    //$where.=" and NOW()<fromtime";
	    $where.=" and shtime+INTERVAL 24 HOUR>NOW() and NOW()>shtime";
	    //$where.=" and time+INTERVAL 48 HOUR>NOW() and NOW()>time+INTERVAL 24 HOUR";
	    $sql="SELECT * FROM ".tablename('zh_gjw_shotpublish') .$where." ORDER BY time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_shotpublish').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);


		if (empty($res)) {
			echo json_encode(array('msg'=>'没有微拍分类数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res) ; $i++) { 
				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$ures[$i]=pdo_get('zh_gjw_register',array('phone'=>$res[$i]['phone']));
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['ulevel_name']=$ures[$i]['level_name'];
				$res[$i]['username']=$ures[$i]['username'];
				$resu=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['cusname']=$resu['cusname'];
				$res[$i]['level_name']=$resu['level_name'];
				$res[$i]['storeimg']=$resu['storeimg'];
				$res[$i]['reputation']=$resu['reputation'];
				$res[$i]['xybzj']=$totalmoney['total_money'];

				//$res[$i]['totimesjc']=strtotime($res[$i]['totime']);
				$res[$i]['totimesjc']=strtotime($res[$i]['shtime'])+86400*3;
				$res[$i]['fromtimesjc']=strtotime($res[$i]['shtime'])+86400;
				$res[$i]['fromtime']=date('Y-m-d H:i:s',$res[$i]['fromtimesjc']);
				//$res[$i]['totimesjc']=strtotime($res[$i]['time'])+86400*4;
				//$res[$i]['fromtimesjc']=strtotime($res[$i]['time'])+86400*2;
			}
			// for ($j=0; $j <count($res) ; $j++) { 
			// 	if (0<strtotime($res[$j]['fromtime'])-time() && strtotime($res[$j]['fromtime'])-time()<2*86400) {
			// 		$res[$j]['totimesjc']=strtotime($res[$j]['totime']);
			// 		$res[$j]['fromtimesjc']=strtotime($res[$j]['fromtime']);
			// 		array_push($arr,$res[$j]);
			// 	}
			// }
			if (empty($res)) {
				echo json_encode(array('msg'=>'微拍分类数据','code'=>'500'),320);exit();
			}
			echo json_encode(array('msg'=>'微拍分类数据','code'=>'200','res'=>$res),320);exit();
		}
	}
	//微拍预展推荐
	public function doPageShotwillupfee(){
		global $_W, $_GPC;
		// $arr=array();
		// $res=pdo_fetchall("SELECT * FROM " . tablename('zh_gjw_shotpublish')."WHERE upfee=1 and state=2 and uniacid=".$_W['uniacid']);

		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE  uniacid=:uniacid and state=:state and upfee=:upfee ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':state']=2;
	    $data[':upfee']=1;
	    //$where.=" and NOW()<fromtime and fromtime<NOW()+INTERVAL 48 HOUR";
	    $where.=" and NOW()<fromtime";
	    $sql="SELECT * FROM ".tablename('zh_gjw_shotpublish') .$where." ORDER BY topfee desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_shotpublish').$where." ORDER BY topfee desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		
		if (empty($res)) {
			echo json_encode(array('msg'=>'没有微拍分类数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res) ; $i++) { 
				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$ures[$i]=pdo_get('zh_gjw_register',array('phone'=>$res[$i]['phone']));
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['username']=$ures[$i]['username'];
				$resu=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone']));
				$res[$i]['cusname']=$resu['cusname'];
				$res[$i]['storeimg']=$resu['storeimg'];

				$res[$i]['totimesjc']=strtotime($res[$i]['totime']);
				$res[$i]['fromtimesjc']=strtotime($res[$i]['fromtime']);
			}
			
			// for ($j=0; $j <count($res) ; $j++) { 
			// 	if (0<strtotime($res[$j]['fromtime'])-time() && strtotime($res[$j]['fromtime'])-time()<2*86400) {
			// 		$res[$j]['totimesjc']=strtotime($res[$j]['totime']);
			// 		$res[$j]['fromtimesjc']=strtotime($res[$j]['fromtime']);
			// 		array_push($arr,$res[$j]);
			// 	}
			// }
			if (empty($res)) {
				echo json_encode(array('msg'=>'微拍推荐数据','code'=>'500'),320);exit();
			}
			echo json_encode(array('msg'=>'微拍推荐数据','code'=>'200','res'=>$res),320);exit();
		}
	}
  
	//微拍三级分类数据
	public function doPageShotcuscateid(){
		global $_W, $_GPC;
		// $arr=array();
		// $res=pdo_getall('zh_gjw_marketpublish',array('cth_id'=>$_GPC['cth_id'],'state'=>2,'uniacid'=>$_W['uniacid']), array() , '' , 'topfee DESC' , array());

		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE  uniacid=:uniacid and state=:state and cth_id=:cth_id ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':state']=2;
	    $data[':cth_id']=$_GPC['cth_id'];
	    // // $where.=" and NOW()<fromtime and fromtime<NOW()+INTERVAL 48 HOUR";
	    // $where.=" and totime >=FROM_UNIXTIME(".time().") and fromtime<=FROM_UNIXTIME(".time().")";
	    $where.=" and shtime+INTERVAL 72 HOUR>NOW() and shtime+INTERVAL 24 HOUR<NOW() ";
	    //$where.=" and time+INTERVAL 96 HOUR>NOW() and time+INTERVAL 48 HOUR<NOW() ";
	    $sql="SELECT * FROM ".tablename('zh_gjw_shotpublish') .$where." ORDER BY time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_shotpublish').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);

		if (empty($res)) {
			echo json_encode(array('msg'=>'没有微拍分类数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res) ; $i++) { 
				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$ures[$i]=pdo_get('zh_gjw_register',array('phone'=>$res[$i]['phone']));//?
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['ulevel_name']=$ures[$i]['level_name'];
				$res[$i]['username']=$ures[$i]['username'];
				$resu=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['cusname']=$resu['cusname'];
				$res[$i]['level_name']=$resu['level_name'];
				$res[$i]['storeimg']=$resu['storeimg'];
				$res[$i]['reputation']=$resu['reputation'];
				$res[$i]['xybzj']=$totalmoney['total_money'];

				$res[$i]['totimesjc']=strtotime($res[$i]['shtime'])+86400*3;
				//$res[$i]['totimesjc']=strtotime($res[$i]['time'])+86400*4;
			}
			// for ($j=0; $j <count($res) ; $j++) { 
			// 	if (0<strtotime($res[$j]['fromtime'])-time() && strtotime($res[$j]['fromtime'])-time()<86400) {
			// 		$res[$j]['totimesjc']=strtotime($res[$j]['totime']);
			// 		array_push($arr,$res[$j]);
			// 	}
			// }
			if (empty($res)) {
				echo json_encode(array('msg'=>'微拍分类数据','code'=>'500'),320);exit();
			}
			echo json_encode(array('msg'=>'微拍分类数据','code'=>'200','res'=>$res),320);exit();
		}
	}
	//微拍分类二级推荐数据
	public function doPageShotsubup(){
		global $_W, $_GPC;
		// $arr=array();
		// $res=pdo_getall('zh_gjw_marketpublish',array('ct_id'=>$_GPC['ct_id'],'state'=>2,'upfee'=>1,'uniacid'=>$_W['uniacid']), array() , '' , 'topfee DESC' , array());

		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE  uniacid=:uniacid and state=:state and upfee=:upfee and ct_id=:ct_id ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':state']=2;
	    $data[':upfee']=1;
	    $data[':ct_id']=$_GPC['ct_id'];
	    // // $where.=" and NOW()<fromtime and fromtime<NOW()+INTERVAL 48 HOUR";
	    // $where.=" and totime >=FROM_UNIXTIME(".time().") and fromtime<=FROM_UNIXTIME(".time().")";
	    $where.=" and shtime+INTERVAL 72 HOUR>NOW() and shtime+INTERVAL 24 HOUR<NOW() ";
	    //$where.=" and time+INTERVAL 96 HOUR>NOW() and time+INTERVAL 48 HOUR<NOW() ";
	    $sql="SELECT * FROM ".tablename('zh_gjw_shotpublish') .$where." ORDER BY uptime desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_shotpublish').$where." ORDER BY uptime desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);

		if (empty($res)) {
			echo json_encode(array('msg'=>'没有微拍分类数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res) ; $i++) { 
				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$ures[$i]=pdo_get('zh_gjw_register',array('phone'=>$res[$i]['phone']));//?
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['ulevel_name']=$ures[$i]['level_name'];
				$res[$i]['username']=$ures[$i]['username'];
				$resu=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone']));
				$res[$i]['cusname']=$resu['cusname'];
				$res[$i]['level_name']=$resu['level_name'];
				$res[$i]['storeimg']=$resu['storeimg'];

				$shot=pdo_getall('zh_gjw_shotbuy',array('shot_id'=>$res[$i]['id'],'uniacid'=>$_W['uniacid']), array() , '' , 'fee DESC' , array());
				if ($shot) {
					$res[$i]['newfee']=$shot[0]['fee'];
				}else{
					$res[$i]['newfee']=0;
				}
				$res[$i]['totimesjc']=strtotime($res[$i]['shtime'])+86400*3;
				//$res[$i]['totimesjc']=strtotime($res[$i]['time'])+86400*4;

			}
			// for ($j=0; $j <count($res) ; $j++) { 
			// 	if (strtotime($res[$j]['totime'])>time() && time()>strtotime($res[$j]['fromtime'])) {
			// 		$res[$j]['totimesjc']=strtotime($res[$j]['totime']);
			// 		array_push($arr,$res[$j]);
			// 	}
			// }
			if (empty($res)) {
				echo json_encode(array('msg'=>'微拍推荐数据','code'=>'500'),320);exit();
			}
			echo json_encode(array('msg'=>'微拍推荐数据','code'=>'200','res'=>$res),320);exit();
		}
	}
  
	//微拍分类二级全部数据
	public function doPageShotsuball(){
		global $_W, $_GPC;
		// $arr=array();
		// $res=pdo_getall('zh_gjw_marketpublish',array('ct_id'=>$_GPC['ct_id'],'state'=>2,'upfee'=>1,'uniacid'=>$_W['uniacid']), array() , '' , 'topfee DESC' , array());

		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE  uniacid=:uniacid and state=:state and ct_id=:ct_id ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':state']=2;
	    $data[':ct_id']=$_GPC['ct_id'];
	    // // $where.=" and NOW()<fromtime and fromtime<NOW()+INTERVAL 48 HOUR";
	    // $where.=" and totime >=FROM_UNIXTIME(".time().") and fromtime<=FROM_UNIXTIME(".time().")";
	    $where.=" and shtime+INTERVAL 72 HOUR>NOW() and shtime+INTERVAL 24 HOUR<NOW() ";
	    //$where.=" and time+INTERVAL 96 HOUR>NOW() and time+INTERVAL 48 HOUR<NOW() ";
	    $sql="SELECT * FROM ".tablename('zh_gjw_shotpublish') .$where." ORDER BY time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_shotpublish').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);

		if (empty($res)) {
			echo json_encode(array('msg'=>'没有微拍分类数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res) ; $i++) { 
				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$ures[$i]=pdo_get('zh_gjw_register',array('phone'=>$res[$i]['phone']));//?
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['ulevel_name']=$ures[$i]['level_name'];
				$res[$i]['username']=$ures[$i]['username'];
				$resu=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['cusname']=$resu['cusname'];
				$res[$i]['level_name']=$resu['level_name'];
				$res[$i]['storeimg']=$resu['storeimg'];
				$res[$i]['reputation']=$resu['reputation'];
				$res[$i]['xybzj']=$totalmoney['total_money'];

				$shot=pdo_getall('zh_gjw_shotbuy',array('shot_id'=>$res[$i]['id'],'uniacid'=>$_W['uniacid']), array() , '' , 'fee DESC' , array());
				if ($shot) {
					$res[$i]['newfee']=$shot[0]['fee'];
				}else{
					$res[$i]['newfee']=0;
				}
				$res[$i]['totimesjc']=strtotime($res[$i]['shtime'])+86400*3;
				//$res[$i]['totimesjc']=strtotime($res[$i]['time'])+86400*4;

			}
			// for ($j=0; $j <count($res) ; $j++) { 
			// 	if (strtotime($res[$j]['totime'])>time() && time()>strtotime($res[$j]['fromtime'])) {
			// 		$res[$j]['totimesjc']=strtotime($res[$j]['totime']);
			// 		array_push($arr,$res[$j]);
			// 	}
			// }
			if (empty($res)) {
				echo json_encode(array('msg'=>'微拍推荐数据','code'=>'500'),320);exit();
			}
			echo json_encode(array('msg'=>'微拍推荐数据','code'=>'200','res'=>$res),320);exit();
		}
	}
	//微拍浏览+1
	public function doPageShotview(){
		global $_GPC, $_W;
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$id=pdo_get('zh_gjw_shotpublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if (empty($id['view'])) {
			pdo_update('zh_gjw_shotpublish', array('view' =>$user['id']), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
			echo json_encode(array('msg'=>'浏览成功','code'=>'200','res'=>1),320);exit();
		}else{
			$ids=explode(",",$id['view']);
			if (in_array($user['id'], $ids)){
				if (in_array(0,$ids)) {
					$idss=count($ids)-1;
				}else{
					$idss=count($ids);
				}
				echo json_encode(array('msg'=>'浏览过了','code'=>'201','res'=>$idss),320);exit();
			}else{
				array_push($ids,$user['id']);
				$view=implode(',', $ids);
				$res = pdo_update('zh_gjw_shotpublish', array('view' =>$view), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
				if (empty($res)) {
					echo json_encode(array('msg'=>'浏览失败','code'=>'500'),320);exit();
				}
				$viewid=pdo_get('zh_gjw_shotpublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
				if (in_array(0,explode(",",$viewid['view']))) {
					$viewids=count(explode(",",$viewid['view']))-1;
				}else{
					$viewids=count(explode(",",$viewid['view']));
				}
				echo json_encode(array('msg'=>'浏览成功','code'=>'200','res'=>$viewids),320);exit();
			}
		}
	}
	//微拍点赞+1
	public function doPageShotagree(){
		global $_GPC, $_W;
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$id=pdo_get('zh_gjw_shotpublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if (empty($id['agree'])) {
			pdo_update('zh_gjw_shotpublish', array('agree' =>$user['id']), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
			echo json_encode(array('msg'=>'点赞成功','code'=>'200','res'=>1),320);exit();
		}else{
			$ids=explode(",",$id['agree']);
			if (in_array($user['id'], $ids)){
				if (in_array(0,$ids)) {
					$idss=count($ids)-1;
				}else{
					$idss=count($ids);
				}
				echo json_encode(array('msg'=>'点赞过了','code'=>'201','res'=>$idss),320);exit();
			}else{
				array_push($ids,$user['id']);
				$agree=implode(',', $ids);
				$res = pdo_update('zh_gjw_shotpublish', array('agree' =>$agree), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
				if (empty($res)) {
					echo json_encode(array('msg'=>'点赞失败','code'=>'500'),320);exit();
				}
				$agreeid=pdo_get('zh_gjw_shotpublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
				if (in_array(0,explode(",",$agreeid['agree']))) {
					$agreeids=count(explode(",",$agreeid['agree']))-1;
				}else{
					$agreeids=count(explode(",",$agreeid['agree']));
				}
				echo json_encode(array('msg'=>'点赞成功','code'=>'200','res'=>$agreeids),320);exit();
			}
		}
	}
	//微拍详情点赞没有
	public function doPageShotagreedetail(){
		global $_W, $_GPC;
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$id=pdo_get('zh_gjw_shotpublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		// if (!empty($id)) {
			$ids=explode(",",$id['agree']);
			if (in_array($user['id'], $ids)){
					echo json_encode(array('msg'=>'点赞过了','code'=>'200'),320);exit();
			}else{
				echo json_encode(array('msg'=>'没有点赞过','code'=>'500'),320);exit();
			}
		// }
	}
  	//微拍出价
	public function doPageShotfee(){
		global $_W,$_GPC;
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$fee=pdo_get('zh_gjw_shotpublish',array('id'=>$_GPC['shot_id'],'uniacid'=>$_W['uniacid']));
		$shot_id=pdo_get('zh_gjw_shotbuy',array('shot_id'=>$_GPC['shot_id'],'u_id'=>$user['id'],'uniacid'=>$_W['uniacid']));
		$shot=pdo_getall('zh_gjw_shotbuy',array('shot_id'=>$_GPC['shot_id'],'uniacid'=>$_W['uniacid']), array() , '' , 'fee DESC' , array());
		$shots=pdo_getall('zh_gjw_shotbuy',array('shot_id'=>$_GPC['shot_id'],'uniacid'=>$_W['uniacid'],'userbzj'=>1), array() , '' , 'fee DESC' , array());
			function ressort($shots){
                  for($i=1;$i<count($shots);$i++)
                   { //该层循环用来控制每轮 冒出一个数 需要比较的次数
                      for($k=0;$k<count($shots)-$i;$k++)
                      {
                         if($shots[$k]['fee']<$shots[$k+1]['fee'])
                          {
                              $tmp=$shots[$k+1];
                              $shots[$k+1]=$shots[$k];
                              $shots[$k]=$tmp;
                          }
                      }
                  }
              return $shots;
            }
			$shots=ressort($shots);
			/*function getaccess_token($_W){
	          $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
	          $appid=$res['appid'];
	          $secret=$res['appsecret'];
	          $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
	          $ch = curl_init();
	          curl_setopt($ch, CURLOPT_URL,$url);
	          curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
	          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
	          $data = curl_exec($ch);
	          curl_close($ch);
	          $data = json_decode($data,true);
	          return $data['access_token'];
	        }*/
	        function set_msg($_W,$res_id){
	            //$access_token = getaccess_token($_W);
	            $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
	            $shotid=pdo_get('zh_gjw_shotbuy',array('id'=>$res_id));
	            $openid=pdo_get('zh_gjw_register',array('id'=>$shotid['u_id']));
	            $title=pdo_get('zh_gjw_shotpublish',array('id'=>$shotid['shot_id']));
	            $formwork ='{
	                "touser": "'.$openid["openid"].'",
	                "template_id": "'.$ress["templeidosc"].'",
	                "form_id":"'.$shotid['formid'].'",
	                "data": {
	                    "keyword1": {
	                        "value": "'.$shotid['fee'].'",
	                        "color": "#173177"
	                    },
	                    "keyword2": {
	                        "value":"'.$title['title'].'",
	                        "color": "#173177"
	                    },
	                    "keyword3": {
	                        "value":"'.$shotid['time'].'",
	                        "color": "#173177"
	                    }
	                }  
	            }';
	            $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
	            $ch = curl_init();
	            curl_setopt($ch, CURLOPT_URL,$url);
	            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
	            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
	            curl_setopt($ch, CURLOPT_POST,1);
	            curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
	            $data = curl_exec($ch);
	            curl_close($ch);
	           return $data;
	        }
		if (empty($shot)) {//一个出价的都没有
				$data['shot_id']=$_GPC['shot_id'];
				$data['formid']=$_GPC['formid'];
				$data['u_id']=$user['id'];
				if ($fee['shotmoney']>0) {
					$data['fee']=$fee['shotmoney'];
				}else{
					$data['fee']=$fee['shotmoney']+$fee['addmoney'];
				}
				$data['uniacid']=$_W['uniacid'];
				$data['time']=date('Y-m-d H:i:s',time());
				$res=pdo_insert('zh_gjw_shotbuy',$data);
				$res_id=pdo_insertid();
		        //set_msg($_W,$res_id);
				if ($res) {
		    		echo json_encode(array('msg'=>'记录成功','code'=>'201','res'=>$res_id),320);exit();
				}else{
					echo json_encode(array('msg'=>'记录失败','code'=>'500'),320);exit();
				}
		}else{
			if (empty($shots)) {//有出价者，没有人出价并支付（也就是没出价成功）
				if (empty($shot_id)) {//有出价者，没有人出价并支付，但是我是第一次
					$data['shot_id']=$_GPC['shot_id'];
					$data['formid']=$_GPC['formid'];
					$data['u_id']=$user['id'];
					if ($fee['shotmoney']>0) {
						$data['fee']=$fee['shotmoney'];
					}else{
						$data['fee']=$fee['shotmoney']+$fee['addmoney'];
					}
					$data['uniacid']=$_W['uniacid'];
					$data['time']=date('Y-m-d H:i:s',time());
					$res=pdo_insert('zh_gjw_shotbuy',$data);
					$res_id=pdo_insertid();
			        //set_msg($_W,$res_id);
					if ($res) {
			    		echo json_encode(array('msg'=>'记录成功','code'=>'202','res'=>$res_id),320);exit();
					}else{
						echo json_encode(array('msg'=>'记录失败','code'=>'500'),320);exit();
					}
				}else{
					//$data['fee']=$shots[0]['fee']+$fee['addmoney'];
					$data['time']=date('Y-m-d H:i:s',time());
					$data['formid']=$_GPC['formid'];
					$res=pdo_update('zh_gjw_shotbuy',$data,array('u_id'=>$user['id'],'shot_id'=>$_GPC['shot_id'],'uniacid'=>$_W['uniacid']));
					if ($res) {
						if($shot_id['userbzj']!=1)
						{
							echo json_encode(array('msg'=>'更新成功','code'=>'203','res'=>$shot_id['id']),320);exit();
						}
					}else{
						echo json_encode(array('msg'=>'更新失败','code'=>'500'),320);exit();
					}
				}
			}else{//有出价者，有人出价并支付
				if (empty($shot_id)) {//有出价者，但是我是第一次
					$data['shot_id']=$_GPC['shot_id'];
					$data['formid']=$_GPC['formid'];
					$data['u_id']=$user['id'];
					$data['fee']=$shots[0]['fee']+$fee['addmoney'];
					$data['uniacid']=$_W['uniacid'];
					$data['time']=date('Y-m-d H:i:s',time());
					$res=pdo_insert('zh_gjw_shotbuy',$data);
					$res_id=pdo_insertid();
			        //set_msg($_W,$res_id);
					if ($res) {
			    		echo json_encode(array('msg'=>'记录成功','code'=>'202','res'=>$res_id),320);exit();
					}else{
						echo json_encode(array('msg'=>'记录失败','code'=>'500'),320);exit();
					}
				}else{
					$data['fee']=$shots[0]['fee']+$fee['addmoney'];
					$data['time']=date('Y-m-d H:i:s',time());
					$data['formid']=$_GPC['formid'];
					$res=pdo_update('zh_gjw_shotbuy',$data,array('u_id'=>$user['id'],'shot_id'=>$_GPC['shot_id'],'uniacid'=>$_W['uniacid']));
					if ($res) {
						if($shot_id['userbzj']!=1)
						{
							echo json_encode(array('msg'=>'更新成功','code'=>'203','res'=>$shot_id['id']),320);exit();
						}else{
							echo json_encode(array('msg'=>'更新成功','code'=>'204'),320);exit();
						}
					}else{
						echo json_encode(array('msg'=>'更新失败','code'=>'500'),320);exit();
					}
				}
			}
			
		}
	}
	//微拍出价支付保证金
	public function doPageShotbzjpay(){
		global $_W,$_GPC;
		$fee=pdo_get('zh_gjw_shotpublish',array('id'=>$_GPC['shot_id'],'uniacid'=>$_W['uniacid']));
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		pdo_update('zh_gjw_shotbuy', array('paycode' =>$out_trade_no), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		$root=$_W['siteroot']; 
		$total_fee =$fee['userbzj'];
		if($total_fee>0)
		{
			$body = "微拍保证金支付";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
		echo json_encode($return);
	}
  //出价支付保证金成功改变状态
	public function doPageShotbzjpaysuccess(){
		global $_W, $_GPC;
		$res = pdo_update('zh_gjw_shotbuy', array('userbzj' =>1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		if ($res) {
			echo json_encode(array('msg'=>'好了','code'=>'200'),320);exit();
		}
		echo json_encode(array('msg'=>'错了','code'=>'500'),320);exit();
	}
	//拍卖详情查询出价者
	public function doPageShotuser(){
		global $_W,$_GPC;
		$res=pdo_fetchall("SELECT a.*,b.avatar,b.username,b.openid FROM " . tablename('zh_gjw_shotbuy'). " a"  . " left join " . tablename("zh_gjw_register") . " b on a.u_id=b.id WHERE  a.shot_id=:shot_id and a.uniacid=:uniacid and a.userbzj=:userbzj", array(':shot_id'=>$_GPC['shot_id'],':uniacid'=>$_W['uniacid'],':userbzj'=>1));
				
      			/*function getaccess_token($_W){
		          $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		          $appid=$res['appid'];
		          $secret=$res['appsecret'];
		          $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
		          $ch = curl_init();
		          curl_setopt($ch, CURLOPT_URL,$url);
		          curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
		          $data = curl_exec($ch);
		          curl_close($ch);
		          $data = json_decode($data,true);
		          return $data['access_token'];
		        }*/
		        function set_msgs($_W,$id0,$id1){
		            //$access_token = getaccess_token($_W);
		            $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		            $shotid0=pdo_get('zh_gjw_shotbuy',array('id'=>$id0));
		            $shotid1=pdo_get('zh_gjw_shotbuy',array('id'=>$id1));
		            $openid=pdo_get('zh_gjw_register',array('id'=>$shotid1['u_id']));
		            $title=pdo_get('zh_gjw_shotpublish',array('id'=>$shotid1['shot_id']));
		            $formwork ='{
		                "touser": "'.$openid["openid"].'",
		                "template_id": "'.$ress["templeidove"].'",
		                "form_id":"'.$shotid1['formid'].'",
		                "data": {
		                    "keyword1": {
		                        "value":"'.$title['title'].'",
		                        "color": "#173177"
		                    },
		                    "keyword2": {
		                        "value": "'.$shotid0['fee'].'",
		                        "color": "#173177"
		                    },
		                    "keyword3": {
		                        "value":"'.$shotid0['time'].'",
		                        "color": "#173177"
		                    }
		                }  
		            }';
		            $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
		            $ch = curl_init();
		            curl_setopt($ch, CURLOPT_URL,$url);
		            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
		            curl_setopt($ch, CURLOPT_POST,1);
		            curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
		            $data = curl_exec($ch);
		            curl_close($ch);
		           return $data;
		        }
		function ressort($res){
			for($i=1;$i<count($res);$i++)
			 { //该层循环用来控制每轮 冒出一个数 需要比较的次数
			    for($k=0;$k<count($res)-$i;$k++)
			    {
			       if($res[$k]['fee']<$res[$k+1]['fee'])
			        {
			            $tmp=$res[$k+1];
			            $res[$k+1]=$res[$k];
			            $res[$k]=$tmp;
			        }
			    }
			}
  		return $res;
		}
		$res=ressort($res);
		if (empty($res)) {
			echo json_encode(array('msg'=>'没有相应出价者','code'=>'500'),320);exit();
		}else{
        	// array_shift($res);
        	
		    set_msgs($_W,$res[0]['id'],$res[1]['id']);
			echo json_encode(array('msg'=>'找到啦','code'=>'200','res'=>$res),320);exit();
		}
	}
	//我的竞拍ing
	public function doPageMyshoting(){
		global $_W,$_GPC;
		$arr=array();
		$openid=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$res=pdo_fetchall("SELECT a.*,b.videoimg,b.img,b.totime,b.title,b.view,b.agree,b.video,b.phone,b.shotmoney,b.addmoney,b.shtime FROM " . tablename('zh_gjw_shotbuy'). " a"  . " left join " . tablename("zh_gjw_shotpublish") . " b on a.shot_id=b.id WHERE  a.u_id=:u_id and a.uniacid=:uniacid and a.userbzj=:userbzj", array(':u_id'=>$openid['id'],':uniacid'=>$_W['uniacid'],':userbzj'=>1));
				
			function ressort($allshot){
				for($j=1;$j<count($allshot);$j++)
				 { //该层循环用来控制每轮 冒出一个数 需要比较的次数
				    for($k=0;$k<count($allshot)-$j;$k++)
				    {
				       if($allshot[$k]['fee']<$allshot[$k+1]['fee'])
				        {
				            $tmp=$allshot[$k+1];
				            $allshot[$k+1]=$allshot[$k];
				            $allshot[$k]=$tmp;
				        }
				    }
				}
	  		return $allshot;
			}
		for ($i=0; $i <count($res) ; $i++) { 

			if (in_array(0,explode(",",$res[$i]['view']))) {
				$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
			}else{
				$res[$i]['view']=count(explode(",",$res[$i]['view']));
			}
			if (in_array(0,explode(",",$res[$i]['agree']))) {
				$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
			}else{
				$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
			}

			$cusname=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone'],'uniacid'=>$_W['uniacid']));
			if ($cusname) {
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $cusname['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['reputation']=$cusname['reputation'];
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['cusname']=$cusname['cusname'];
				$res[$i]['level_name']=$cusname['level_name'];
				$res[$i]['storeimg']=$cusname['storeimg'];
			}else{
				$res[$i]['cusname']='';
				$res[$i]['storeimg']='';
			}

			$allshot=pdo_getall('zh_gjw_shotbuy',array('shot_id'=>$res[$i]['shot_id']));
			
			$allshot=ressort($allshot);
			$res[$i]['max']=$allshot[0]['fee'];
			$res[$i]['totimesjc']=strtotime($res[$i]['shtime'])+86400*4;
			$res[$i]['totime']=date('Y-m-d H:i:s',$res[$i]['totimesjc']);
			if (strtotime($res[$i]['shtime'])+86400*4>time()) {
				array_push($arr,$res[$i]);
			}
		}

		if (empty($arr)) {
			echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
		}else{
			echo json_encode(array('msg'=>'找到啦','code'=>'200','res'=>$arr),320);exit();
		}
	}
	//我的竞拍待支付
	public function doPageMyshottopay(){
		global $_W,$_GPC;
		$arr=array();
		$openid=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$res=pdo_fetchall("SELECT a.*,b.videoimg,b.img,b.totime,b.title,b.view,b.agree,b.video,b.phone,b.shotmoney,b.addmoney,b.exfee,b.shtime FROM " . tablename('zh_gjw_shotbuy'). " a"  . " left join " . tablename("zh_gjw_shotpublish") . " b on a.shot_id=b.id WHERE  a.u_id=:u_id and a.uniacid=:uniacid and a.userbzj=:userbzj", array(':u_id'=>$openid['id'],':uniacid'=>$_W['uniacid'],':userbzj'=>1));
			function ressort($allshot){
				for($j=1;$j<count($allshot);$j++)
				 { //该层循环用来控制每轮 冒出一个数 需要比较的次数
				    for($k=0;$k<count($allshot)-$j;$k++)
				    {
				       if($allshot[$k]['fee']<$allshot[$k+1]['fee'])
				        {
				            $tmp=$allshot[$k+1];
				            $allshot[$k+1]=$allshot[$k];
				            $allshot[$k]=$tmp;
				        }
				    }
				}
	  			return $allshot;
			}
		for ($i=0; $i <count($res) ; $i++) { 

			if (in_array(0,explode(",",$res[$i]['view']))) {
				$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
			}else{
				$res[$i]['view']=count(explode(",",$res[$i]['view']));
			}
			if (in_array(0,explode(",",$res[$i]['agree']))) {
				$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
			}else{
				$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
			}

			$cusname=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone'],'uniacid'=>$_W['uniacid']));
			if ($cusname) {
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $cusname['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['reputation']=$cusname['reputation'];
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['cusname']=$cusname['cusname'];
				$res[$i]['level_name']=$cusname['level_name'];
				$res[$i]['storeimg']=$cusname['storeimg'];
			}else{
				$res[$i]['cusname']='';
				$res[$i]['storeimg']='';
			}

			$allshot=pdo_getall('zh_gjw_shotbuy',array('shot_id'=>$res[$i]['shot_id']));
			
			$allshot=ressort($allshot);
			$res[$i]['max']=$allshot[0]['fee'];
			$res[$i]['totimesjc']=strtotime($res[$i]['shtime'])+86400*3;
			if (strtotime($res[$i]['shtime'])+86400*3<time() && time()<strtotime($res[$i]['shtime'])+86400*5 && $res[$i]['pay']!=1) {
				array_push($arr,$res[$i]);
			}
		}

		if (empty($arr)) {
			echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
		}else{
			if ($arr[0]['max']==$arr[0]['fee']) {
				echo json_encode(array('msg'=>'找到啦','code'=>'200','res'=>$arr),320);exit();
			}
			echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
		}
	}
	//我的竞拍结束
	public function doPageMyshotover(){
		global $_W,$_GPC;
		$arr=array();
		$openid=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$res=pdo_fetchall("SELECT a.*,b.videoimg,b.img,b.totime,b.title,b.view,b.agree,b.video,b.phone,b.shotmoney,b.addmoney FROM " . tablename('zh_gjw_shotbuy'). " a"  . " left join " . tablename("zh_gjw_shotpublish") . " b on a.shot_id=b.id WHERE  a.u_id=:u_id and a.uniacid=:uniacid", array(':u_id'=>$openid['id'],':uniacid'=>$_W['uniacid']));
			function ressort($allshot){
				for($j=1;$j<count($allshot);$j++)
				 { //该层循环用来控制每轮 冒出一个数 需要比较的次数
				    for($k=0;$k<count($allshot)-$j;$k++)
				    {
				       if($allshot[$k]['fee']<$allshot[$k+1]['fee'])
				        {
				            $tmp=$allshot[$k+1];
				            $allshot[$k+1]=$allshot[$k];
				            $allshot[$k]=$tmp;
				        }
				    }
				}
	  		return $allshot;
			}
		for ($i=0; $i <count($res) ; $i++) { 

			if (in_array(0,explode(",",$res[$i]['view']))) {
				$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
			}else{
				$res[$i]['view']=count(explode(",",$res[$i]['view']));
			}
			if (in_array(0,explode(",",$res[$i]['agree']))) {
				$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
			}else{
				$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
			}

			$cusname=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone'],'uniacid'=>$_W['uniacid']));
			if ($cusname) {
				$res[$i]['cusname']=$cusname['cusname'];
				$res[$i]['storeimg']=$cusname['storeimg'];
			}else{
				$res[$i]['cusname']='';
				$res[$i]['storeimg']='';
			}

			$allshot=pdo_getall('zh_gjw_shotbuy',array('shot_id'=>$res[$i]['shot_id']));
			
			$allshot=ressort($allshot);
			$res[$i]['max']=$allshot[0]['fee'];
			$res[$i]['totimesjc']=strtotime($res[$i]['totime']);
			if (strtotime($res[$i]['totime'])<time() && $res[$i]['pay']==1) {
				array_push($arr,$res[$i]);
			}
		}

		if (empty($arr)) {
			echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
		}else{
			echo json_encode(array('msg'=>'找到啦','code'=>'200','res'=>$arr),320);exit();
		}
	}
	//生成微拍订单
	public function doPageShotorder(){
		global $_W,$_GPC;
		$cus_id=pdo_get('zh_gjw_shotpublish',array('id'=>$_GPC['p_id']));
		$cusm=pdo_get('zh_gjw_cusmanage',array('phone'=>$cus_id['phone']));
		$u_id=pdo_get('zh_gjw_register',array('uniacid'=>$_W['uniacid'],'openid'=>$_GPC['openid']));
		$data['u_id']=$u_id['id'];
		$data['cus_id']=$cusm['id'];
		$data['formid']=$_GPC['formid'];
		$data['p_id']=$_GPC['p_id'];
		$data['type']=$_GPC['type'];
		$data['ordernum']=date('Ymdhis').$u_id['id'].rand(10,99);
		$data['ofee']=$_GPC['ofee'];
		$data['message']=$_GPC['message'];
		$data['phone']=$_GPC['phone'];
		$data['uname']=$_GPC['name'];
		$data['state']=1;
		$data['address']=$_GPC['address'];
		$data['num']=$_GPC['num'];
		$data['ofees']=$_GPC['ofees'];
		$data['uniacid']=$_W['uniacid'];
		$data['time']=date('Y-m-d H:i:s',time());
		$data['timesjc']=time();
		$exuser=pdo_get('zh_gjw_orders',array('uniacid'=>$_W['uniacid'],'u_id'=>$u_id['id'],'p_id'=>$_GPC['p_id'],'type'=>$_GPC['type']));
		if ($exuser) {
			echo json_encode(array('msg'=>'提交成功','code'=>'200','res_id'=>$exuser['id']),320);exit();
		}
		$res=pdo_insert('zh_gjw_orders',$data);
		$res_id=pdo_insertid();
		if (empty($res)) {
			echo json_encode(array('msg'=>'提交失败','code'=>'500'),320);exit();
		}
		echo json_encode(array('msg'=>'提交成功','code'=>'200','res_id'=>$res_id),320);exit();

	}
	//微拍订单支付
	public function doPageShotorderpay(){
		global $_W,$_GPC;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		pdo_update('zh_gjw_orders', array('paycode' =>$out_trade_no), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		$root=$_W['siteroot']; 
		$total_fee =$_GPC['ofees'];
		if($total_fee>0)
		{
			$body = "微拍订单支付";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
		echo json_encode($return);
	}

	//微拍订单支付成功改变state
	public function doPageShotorderpaysuccess(){
		global $_W, $_GPC;
		include_once IA_ROOT . '/addons/zh_gjw/cert/WxPay.Api.php';
	    load()->model('account');
	    load()->func('communication');
	    $WxPayApi = new WxPayApi();
	    $input = new WxPayRefund();
	    $path_cert = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_cert_' . $_W['uniacid'] . '.pem';
	    $path_key = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
		/*function getaccess_token($_W){
          $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
          $appid=$res['appid'];
          $secret=$res['appsecret'];
          $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL,$url);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
          $data = curl_exec($ch);
          curl_close($ch);
          $data = json_decode($data,true);
          return $data['access_token'];
        }*/
        function set_msg($_W,$res){
            //$access_token = getaccess_token($_W);
            $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
            $user=pdo_get('zh_gjw_register',array('id'=>$res['u_id']));
            $orders=pdo_get('zh_gjw_orders',array('id'=>$res['id']));
            $shotname=pdo_get('zh_gjw_shotpublish',array('id'=>$res['p_id']));
            $formwork ='{
                "touser": "'.$user["openid"].'",
                "template_id": "'.$ress["templeidos"].'",
                "form_id":"'.$orders['formid'].'",
                "data": {
                    "keyword1": {
                        "value": "'.$orders['time'].'",
                        "color": "#173177"
                    },
                    "keyword2": {
                        "value":"'.$orders['paytime'].'",
                        "color": "#173177"
                    },
                    "keyword3": {
                        "value":"'.$shotname['title'].'",
                        "color": "#173177"
                    },
                    "keyword4": {
                        "value":"'.$orders['ordernum'].'",
                        "color": "#173177"
                    },
                    "keyword5": {
                        "value":"'.$orders['ofees'].'",
                        "color": "#173177"
                    },
                    "keyword6": {
                        "value":"'.$orders['id'].'",
                        "color": "#173177"
                    },
                    "keyword7": {
                        "value":"微拍购买成功",
                        "color": "#173177"
                    }
                }  
            }';
            $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL,$url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
            curl_setopt($ch, CURLOPT_POST,1);
            curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
            $data = curl_exec($ch);
            curl_close($ch);
           return $data;
        }
        function set_msgs($_W,$res_id,$bzj){
            //$access_token = getaccess_token($_W);
            $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
            $openid=pdo_get('zh_gjw_register',array('id'=>$res_id['u_id']));
            $cusname=pdo_get('zh_gjw_cusmanage',array('openid'=>$openid['openid']));
            $formwork ='{
                "touser": "'.$openid["openid"].'",
                "template_id": "'.$ress["templeidbzj"].'",
                "form_id":"'.$res_id['formid'].'",
                "data": {
                    "keyword1": {
                        "value": "保证金退还",
                        "color": "#173177"
                    },
                    "keyword2": {
                        "value":"'.$bzj.'",
                        "color": "#173177"
                    }
                }  
            }';
            $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL,$url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
            curl_setopt($ch, CURLOPT_POST,1);
            curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
            $data = curl_exec($ch);
            curl_close($ch);
           return $data;
        }
		$res = pdo_update('zh_gjw_orders', array('state' =>2,'paytime' =>date('Y-m-d H:i:s')), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		if ($res) {
			set_msg($_W,$res);
						$syst=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
						$shotbuy=pdo_get('zh_gjw_shotbuy',array('id'=>$_GPC['id']));
						$shotpublish=pdo_get('zh_gjw_shotpublish',array('id'=>$shotbuy['shot_id']));
			            $appid=$syst['appid'];
			            $key=$syst['apikey'];
			            $mchid=$syst['mac_id'];
			            $out_trade_no=$shotbuy['paycode'];//商户订单号
			            $fee = $shotpublish['userbzj'] * 100;
			            $input->SetAppid($appid);
			            $input->SetMch_id($mchid);
			            $input->SetOp_user_id($mchid);
			            $input->SetRefund_fee($fee);
			            $input->SetTotal_fee($fee);
			            $input->SetOut_refund_no($shotbuy['paycode']);
			            $input->SetOut_trade_no($out_trade_no);
			            $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key);
			            if ($result['result_code'] == 'SUCCESS') {//退款成功
			                set_msgs($_W,$shotbuy,$fee);
							pdo_update('zh_gjw_shotbuy', array('pay' =>1,'userbzj' =>3), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
			            }else{
			                message($result['err_code_des'],'','error');
			            }
                file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=GetGrade&m=zh_gjw&order_id=" . $_GPC['res_id']);//修改等级
			echo json_encode(array('msg'=>'成功','code'=>'200'),320);exit();
		}
		echo json_encode(array('msg'=>'失败','code'=>'500'),320);exit();
	}
	//拍卖规则
	public function doPageShotrule(){
		global $_W, $_GPC;
		$shotrule=pdo_getall('zh_gjw_shotrule',array('uniacid'=>$_W['uniacid']));
		if (empty($shotrule)) {
			echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
		}else{
			echo json_encode(array('msg'=>'有数据','code'=>'200','res'=>$shotrule),320);exit();
		}
	}
	//地摊规则
	public function doPageMarketrule(){
		global $_W, $_GPC;
		$marketrule=pdo_getall('zh_gjw_marketrule',array('uniacid'=>$_W['uniacid']));
		if (empty($marketrule)) {
			echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
		}else{
			echo json_encode(array('msg'=>'有数据','code'=>'200','res'=>$marketrule),320);exit();
		}
	}
	//是否注册
	public function doPageIsregister(){
		global $_W, $_GPC;
		$openid=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		if (empty($openid)) {
			echo json_encode(array('msg'=>'没有注册','code'=>'500'),320);exit();
		}else{
			echo json_encode(array('msg'=>'注册过了','code'=>'200','res'=>$openid),320);exit();
		}
	}
	//是否商家
	public function doPageIscustomers(){
		global $_W, $_GPC;
      	if($_GPC['phone']){
			$openid=pdo_get('zh_gjw_cusmanage',array('phone'=>$_GPC['phone'],'uniacid'=>$_W['uniacid']));
        }else{
			$openid=pdo_get('zh_gjw_cusmanage',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
        }
		if (empty($openid)) {
			echo json_encode(array('msg'=>'没有注册','code'=>'500'),320);exit();
		}elseif($openid['sh']==2){
			if ($openid['type']==1) {
				echo json_encode(array('msg'=>'注册认证了并且审核通过,是定制商家身份','code'=>'200','res'=>$openid),320);exit();
			}else{
				echo json_encode(array('msg'=>'注册认证了并且审核通过,是普通商家身份','code'=>'204','res'=>$openid),320);exit();
			}
		}elseif($openid['sh']==1){
			echo json_encode(array('msg'=>'注册认证了，审核未通过','code'=>'201','res'=>$openid),320);exit();
		}elseif($openid['sh']==3){
			echo json_encode(array('msg'=>'注册认证了，审核被拒','code'=>'202','res'=>$openid),320);exit();
		}else{
			echo json_encode(array('msg'=>'好像是出错了','code'=>'501'),320);exit();
		}
	}
	//添加地址
	public function doPageAddaddress(){
		global $_W, $_GPC;
		if ($_GPC['id']) {
			$data['addressname']=$_GPC['addressname'];
			$data['phone']=$_GPC['phone'];
			$data['address']=$_GPC['address'];
			$data['addressdetail']=$_GPC['addressdetail'];
			$u_id=pdo_get('zh_gjw_address',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
			$alladdress=pdo_getall('zh_gjw_address',array('u_id'=>$u_id['u_id'],'uniacid'=>$_W['uniacid']));
			if ($_GPC['state']==1) {
				for ($i=0; $i <count($alladdress) ; $i++) { 
					pdo_update('zh_gjw_address', array('state'=>0), array('id' =>$alladdress[$i]['id'],'uniacid'=>$_W['uniacid']));
				}
			}
			$data['state']=$_GPC['state'];
			$data['uniacid']=$_W['uniacid'];
			$res=pdo_update('zh_gjw_address', $data, array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
			if (empty($res)) {
				echo json_encode(array('msg'=>'编辑地址失败','code'=>'500'),320);exit();
			}else{
				echo json_encode(array('msg'=>'编辑地址成功','code'=>'200'),320);exit();
			}
		}else{
			$openid=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
			$data['u_id']=$openid['id'];
			$data['addressname']=$_GPC['addressname'];
			$data['phone']=$_GPC['phone'];
			$data['address']=$_GPC['address'];
			$data['addressdetail']=$_GPC['addressdetail'];
			$alladdress=pdo_getall('zh_gjw_address',array('u_id'=>$openid['id'],'uniacid'=>$_W['uniacid']));
			if ($_GPC['state']==1) {
				for ($i=0; $i <count($alladdress) ; $i++) { 
					pdo_update('zh_gjw_address', array('state'=>0), array('id' =>$alladdress[$i]['id'],'uniacid'=>$_W['uniacid']));
				}
			}
			$data['state']=$_GPC['state'];
			$data['uniacid']=$_W['uniacid'];
			$res=pdo_insert('zh_gjw_address',$data);
			if (empty($res)) {
				echo json_encode(array('msg'=>'添加失败','code'=>'500'),320);exit();
			}else{
				echo json_encode(array('msg'=>'添加成功','code'=>'200'),320);exit();
			}
		}
	}

	//地址列表
	public function doPageAddresslist(){
		global $_W, $_GPC;
		$openid=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$address=pdo_getall('zh_gjw_address',array('u_id'=>$openid['id'],'uniacid'=>$_W['uniacid']));
		if (empty($address)) {
			echo json_encode(array('msg'=>'没有相应地址','code'=>'500'),320);exit();
		}else{
			echo json_encode(array('msg'=>'找到啦','code'=>'200','res'=>$address),320);exit();
		}
	}
	//地址列表页选中默认地址
	public function doPageAddressstate(){
		global $_W, $_GPC;
		$openid=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$alladdress=pdo_getall('zh_gjw_address',array('u_id'=>$openid['id'],'uniacid'=>$_W['uniacid']));
		for ($i=0; $i <count($alladdress) ; $i++) { 
			pdo_update('zh_gjw_address', array('state'=>0), array('id' =>$alladdress[$i]['id'],'uniacid'=>$_W['uniacid']));
		}
		$res=pdo_update('zh_gjw_address', array('state'=>1), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if (empty($res)) {
			echo json_encode(array('msg'=>'改变失败','code'=>'500'),320);exit();
		}else{
			echo json_encode(array('msg'=>'改变成功','code'=>'200'),320);exit();
		}
	}

	//地址详情
	public function doPageAddressdetail(){
		global $_W, $_GPC;
		$address=pdo_get('zh_gjw_address',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if (empty($address)) {
			echo json_encode(array('msg'=>'没有相应地址','code'=>'500'),320);exit();
		}else{
			echo json_encode(array('msg'=>'找到啦','code'=>'200','res'=>$address),320);exit();
		}
	}

	//地址删除
	public function doPageAddressdel(){
		global $_W, $_GPC;
		$res=pdo_delete('zh_gjw_address',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if ($res) {
			$openid=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
			$address=pdo_getall('zh_gjw_address',array('u_id'=>$openid['id'],'uniacid'=>$_W['uniacid']));
			echo json_encode(array('msg'=>'删除成功','code'=>'200','res'=>$address),320);exit();
		}else{
			echo json_encode(array('msg'=>'删除失败','code'=>'500'),320);exit();
		}
	}
    //定制费
    public function doPagePrimoney(){
    	global $_GPC,$_W;
    	$primoney=pdo_get('zh_gjw_primoney',array('uniacid'=>$_W['uniacid']));
    	if (empty($primoney)) {
    		echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
    	}elseif($primoney){
    		echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$primoney),320);exit();
    	}
    }

    //发布定制
    public function doPagePripublish(){
    	global $_GPC,$_W;
    	$openid=pdo_get('zh_gjw_cusmanage',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
    	$phone=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
    	/*function getaccess_token($_W){
          $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
          $appid=$res['appid'];
          $secret=$res['appsecret'];
          $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL,$url);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
          $data = curl_exec($ch);
          curl_close($ch);
          $data = json_decode($data,true);
          return $data['access_token'];
        }*/
        function set_msg($_W,$id){
            //$access_token = getaccess_token($_W);
            $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
            $openid=pdo_get('zh_gjw_pripublish',array('id'=>$id));
            $formwork ='{
                "touser": "'.$openid["openid"].'",
                "template_id": "'.$ress["templeid"].'",
                "form_id":"'.$openid['formid'].'",
                "data": {
                    "keyword1": {
                        "value": "'.$openid['title'].'",
                        "color": "#173177"
                    },
                    "keyword2": {
                        "value":"定制审核通过",
                        "color": "#173177"
                    }
                }  
            }';
            $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL,$url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
            curl_setopt($ch, CURLOPT_POST,1);
            curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
            $data = curl_exec($ch);
            curl_close($ch);
           return $data;
        }
    	/*if ($openid['sh']==2) {
			$data['pay']=1;
    	}else{
    		$data['pay']=2;
    	}*/
      	
    	/*if ($_GPC['store_identity']==1) {
			$data['pay']=2;
    	}else{
    		$data['pay']=1;
    	}*/
      	$data['pay']=1;
		$data['type']=$_GPC['store_identity'];
		$data['formid']=$_GPC['formid'];
		$data['openid']=$_GPC['openid'];
		$data['title']=$_GPC['title'];
		$data['content']=$_GPC['content'];
		$data['c_id']=$_GPC['c_id'];
		$data['img']=$_GPC['img'];
		$data['state']=1;
		$data['phone']=$phone['phone'];
		$data['uniacid']=$_W['uniacid'];
		$data['time']=date('Y-m-d H:i:s',time());
		$res=pdo_insert('zh_gjw_pripublish',$data);
		$res_id=pdo_insertid();
    	if ($res) {
			$shset=pdo_get('zh_gjw_shset',array('uniacid'=>$_W['uniacid']));
    		if ($shset['prishset']!=1) {
    			pdo_update('zh_gjw_pripublish', array('state' =>2), array('id' =>$res_id,'uniacid'=>$_W['uniacid']));
    			set_msg($_W,$res_id);
    		}
    		echo json_encode(array('msg'=>'发布成功','code'=>'200','res_id'=>$res_id),320);exit();
		}else{
			echo json_encode(array('msg'=>'发布失败','code'=>'500'),320);exit();
		}
    }
    //定制支付
	public function doPagePripay(){
		global $_W, $_GPC;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
    	$openid=pdo_get('zh_gjw_cusmanage',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$res_fee=0;
    	if ($openid) {
			$res_fee=$_GPC['publishfee'];
    	}
		if ($_GPC['upstate']==1) {
			$res_fee=$res_fee+$_GPC['upfee'];
		}
		if($_GPC['alltype']==18){
			$res_fee=$_GPC['upfee'];
		}
		if($_GPC['alltype']==24){
			$res_fee=$_GPC['publishfee'];
		}
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		pdo_update('zh_gjw_pripublish', array('paycode' =>$out_trade_no,'payfee' =>$res_fee), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		$root=$_W['siteroot']; 
		$total_fee =$res_fee;
		if($total_fee>0)
		{
			$body = "定制发布";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
		echo json_encode($return);
	}

	//定制支付成功改变state
	public function doPagePrisuccess(){
		global $_W, $_GPC;
		file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=GetGradeprip&m=zh_gjw&order_id=" . $_GPC['res_id']);//修改等级
		$shset=pdo_get('zh_gjw_shset',array('uniacid'=>$_W['uniacid']));
		/*if ($shset['prishset']==1) {
			if ($_GPC['upstate']==1) {
				pdo_update('zh_gjw_pripublish', array('pay' => 2,'upfee' => 1,'topfee' => 1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
			}
			$res = pdo_update('zh_gjw_pripublish', array('pay' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		}else{
			if ($_GPC['upstate']==1) {
				pdo_update('zh_gjw_pripublish', array('pay' => 2,'upfee' => 1,'topfee' => 1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
			}
			$res = pdo_update('zh_gjw_pripublish', array('pay' => 2,'state'=>2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		}*/
      	if ($shset['prishset']==1) {
			if ($_GPC['upstate']==1) {
				if ($_GPC['alltype']==6) {
					pdo_update('zh_gjw_pripublish', array('alltype' => 6,'pay' => 2,'upfee' =>1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
					$data['openid']=$_GPC['openid'];
					$data['type']=17;
					$data['uniacid']=$_W['uniacid'];
					$data['number']=1;
					$data['sjc']=time();
					$data['time']=date('Y-m-d H:i:s',time());
					pdo_insert('zh_gjw_repucost',$data);
				}
				if ($_GPC['alltype']==10) {
					pdo_update('zh_gjw_pripublish', array('alltype' => 10,'pay' => 2,'upfee' =>1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
					$data['openid']=$_GPC['openid'];
					$data['type']=17;
					$data['uniacid']=$_W['uniacid'];
					$data['number']=1;
					$data['sjc']=time();
					$data['time']=date('Y-m-d H:i:s',time());
					pdo_insert('zh_gjw_repucost',$data);
				}
				if ($_GPC['alltype']==16) {
					pdo_update('zh_gjw_pripublish', array('alltype' => 16,'pay' => 2,'upfee' =>1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
					$data['openid']=$_GPC['openid'];
					$data['type']=15;
					$data['uniacid']=$_W['uniacid'];
					$data['number']=1;
					$data['sjc']=time();
					$data['time']=date('Y-m-d H:i:s',time());
					pdo_insert('zh_gjw_repucost',$data);
				}
				if ($_GPC['alltype']==18) {
					pdo_update('zh_gjw_pripublish', array('alltype' => 18,'pay' => 2,'upfee' =>1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
					$data['openid']=$_GPC['openid'];
					$data['type']=5;
					$data['uniacid']=$_W['uniacid'];
					$data['number']=1;
					$data['sjc']=time();
					$data['time']=date('Y-m-d H:i:s',time());
					pdo_insert('zh_gjw_repucost',$data);
				}
				if ($_GPC['alltype']==20) {
					pdo_update('zh_gjw_pripublish', array('alltype' => 20,'pay' => 2,'upfee' =>1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
					$data['openid']=$_GPC['openid'];
					$data['type']=15;
					$data['uniacid']=$_W['uniacid'];
					$data['number']=1;
					$data['sjc']=time();
					$data['time']=date('Y-m-d H:i:s',time());
					pdo_insert('zh_gjw_repucost',$data);
				}
				if ($_GPC['alltype']==21) {
					pdo_update('zh_gjw_pripublish', array('alltype' => 21,'pay' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
					$data['openid']=$_GPC['openid'];
					$data['type']=5;
					$data['uniacid']=$_W['uniacid'];
					$data['number']=1;
					$data['sjc']=time();
					$data['time']=date('Y-m-d H:i:s',time());
					pdo_insert('zh_gjw_repucost',$data);
				}
				if ($_GPC['alltype']==22) {
					pdo_update('zh_gjw_pripublish', array('alltype' => 22,'pay' => 2,'upfee' =>1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
					$data['openid']=$_GPC['openid'];
					$data['type']=5;
					$data['uniacid']=$_W['uniacid'];
					$data['number']=1;
					$data['sjc']=time();
					$data['time']=date('Y-m-d H:i:s',time());
					pdo_insert('zh_gjw_repucost',$data);
					$datas['openid']=$_GPC['openid'];
					$datas['type']=15;
					$datas['uniacid']=$_W['uniacid'];
					$datas['number']=1;
					$datas['sjc']=time();
					$datas['time']=date('Y-m-d H:i:s',time());
					pdo_insert('zh_gjw_repucost',$datas);
				}
				if ($_GPC['alltype']==24) {
					pdo_update('zh_gjw_pripublish', array('alltype' => 24,'pay' => 2,'upfee' =>1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
					$data['openid']=$_GPC['openid'];
					$data['type']=15;
					$data['uniacid']=$_W['uniacid'];
					$data['number']=1;
					$data['sjc']=time();
					$data['time']=date('Y-m-d H:i:s',time());
					pdo_insert('zh_gjw_repucost',$data);
				}
				pdo_update('zh_gjw_pripublish', array('pay' => 2,'upfee' => 1,'topfee' => 1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
			}

			if ($_GPC['alltype']==17) {
				pdo_update('zh_gjw_pripublish', array('alltype' => 17,'pay' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
				$data['openid']=$_GPC['openid'];
				$data['type']=5;
				$data['uniacid']=$_W['uniacid'];
				$data['number']=1;
				$data['sjc']=time();
				$data['time']=date('Y-m-d H:i:s',time());
				pdo_insert('zh_gjw_repucost',$data);
			}
			$res = pdo_update('zh_gjw_pripublish', array('pay' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		}else{
			if ($_GPC['upstate']==1) {
				if ($_GPC['alltype']==6) {
					pdo_update('zh_gjw_pripublish', array('alltype' => 6,'pay' => 2,'upfee' =>1,'state'=>2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
					$data['openid']=$_GPC['openid'];
					$data['type']=17;
					$data['uniacid']=$_W['uniacid'];
					$data['number']=1;
					$data['sjc']=time();
					$data['time']=date('Y-m-d H:i:s',time());
					pdo_insert('zh_gjw_repucost',$data);
				}
				if ($_GPC['alltype']==10) {
					pdo_update('zh_gjw_pripublish', array('alltype' => 10,'pay' => 2,'upfee' =>1,'state'=>2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
					$data['openid']=$_GPC['openid'];
					$data['type']=17;
					$data['uniacid']=$_W['uniacid'];
					$data['number']=1;
					$data['sjc']=time();
					$data['time']=date('Y-m-d H:i:s',time());
					pdo_insert('zh_gjw_repucost',$data);
				}
				if ($_GPC['alltype']==16) {
					pdo_update('zh_gjw_pripublish', array('alltype' => 16,'pay' => 2,'upfee' =>1,'state'=>2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
					$data['openid']=$_GPC['openid'];
					$data['type']=15;
					$data['uniacid']=$_W['uniacid'];
					$data['number']=1;
					$data['sjc']=time();
					$data['time']=date('Y-m-d H:i:s',time());
					pdo_insert('zh_gjw_repucost',$data);
				}
				if ($_GPC['alltype']==18) {
					pdo_update('zh_gjw_pripublish', array('alltype' => 18,'pay' => 2,'upfee' =>1,'state'=>2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
					$data['openid']=$_GPC['openid'];
					$data['type']=5;
					$data['uniacid']=$_W['uniacid'];
					$data['number']=1;
					$data['sjc']=time();
					$data['time']=date('Y-m-d H:i:s',time());
					pdo_insert('zh_gjw_repucost',$data);
				}
				if ($_GPC['alltype']==20) {
					pdo_update('zh_gjw_pripublish', array('alltype' => 20,'pay' => 2,'upfee' =>1,'state'=>2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
					$data['openid']=$_GPC['openid'];
					$data['type']=15;
					$data['uniacid']=$_W['uniacid'];
					$data['number']=1;
					$data['sjc']=time();
					$data['time']=date('Y-m-d H:i:s',time());
					pdo_insert('zh_gjw_repucost',$data);
				}
				if ($_GPC['alltype']==21) {
					pdo_update('zh_gjw_pripublish', array('alltype' => 21,'pay' => 2,'state'=>2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
					$data['openid']=$_GPC['openid'];
					$data['type']=5;
					$data['uniacid']=$_W['uniacid'];
					$data['number']=1;
					$data['sjc']=time();
					$data['time']=date('Y-m-d H:i:s',time());
					pdo_insert('zh_gjw_repucost',$data);
				}
				if ($_GPC['alltype']==22) {
					pdo_update('zh_gjw_pripublish', array('alltype' => 22,'pay' => 2,'upfee' =>1,'state'=>2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
					$data['openid']=$_GPC['openid'];
					$data['type']=5;
					$data['uniacid']=$_W['uniacid'];
					$data['number']=1;
					$data['sjc']=time();
					$data['time']=date('Y-m-d H:i:s',time());
					pdo_insert('zh_gjw_repucost',$data);
					$datas['openid']=$_GPC['openid'];
					$datas['type']=15;
					$datas['uniacid']=$_W['uniacid'];
					$datas['number']=1;
					$datas['sjc']=time();
					$datas['time']=date('Y-m-d H:i:s',time());
					pdo_insert('zh_gjw_repucost',$datas);
				}
				if ($_GPC['alltype']==24) {
					pdo_update('zh_gjw_pripublish', array('alltype' => 24,'pay' => 2,'upfee' =>1,'state'=>2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
					$data['openid']=$_GPC['openid'];
					$data['type']=15;
					$data['uniacid']=$_W['uniacid'];
					$data['number']=1;
					$data['sjc']=time();
					$data['time']=date('Y-m-d H:i:s',time());
					pdo_insert('zh_gjw_repucost',$data);
				}
				pdo_update('zh_gjw_pripublish', array('pay' => 2,'upfee' => 1,'topfee' => 1,'state'=>2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
			}

			if ($_GPC['alltype']==17) {
				pdo_update('zh_gjw_pripublish', array('alltype' => 17,'pay' => 2,'state'=>2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
				$data['openid']=$_GPC['openid'];
				$data['type']=5;
				$data['uniacid']=$_W['uniacid'];
				$data['number']=1;
				$data['sjc']=time();
				$data['time']=date('Y-m-d H:i:s',time());
				pdo_insert('zh_gjw_repucost',$data);
			}
			$res = pdo_update('zh_gjw_pripublish', array('pay' => 2,'state'=>2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		}
		echo json_encode(array('msg'=>'嗨','code'=>'200','res'=>$res),320);exit();
	}

	//定制商家分类数据全部
	// public function doPagePricall(){
	// 	global $_W, $_GPC;
	// 	$res=pdo_getall('zh_gjw_pripublish',array('state'=>2,'type'=>2,'uniacid'=>$_W['uniacid']));
	// 	if (empty($res)) {
	// 		echo json_encode(array('msg'=>'没有定制商家分类数据','code'=>'500'),320);exit();
	// 	}else{
	// 		for ($i=0; $i <count($res) ; $i++) { 
	// 			$viewids=explode(",",$res[$i]['view']);
	// 			if (in_array(0, $viewids)){
	// 				$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
	// 			}else{
	// 				$res[$i]['view']=count(explode(",",$res[$i]['view']));
	// 			}
	// 		}
	// 		echo json_encode(array('msg'=>'定制分类数据','code'=>'200','res'=>$res),320);exit();
	// 	}
	// }
	//定制商家分类数据推荐
	public function doPagePricup(){
		global $_W, $_GPC;

		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE  uniacid=:uniacid and state=:state and type=:type and upfee=:upfee ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':state']=2;
	    $data[':type']=2;
	    $data[':upfee']=1;
	    $sql="SELECT * FROM ".tablename('zh_gjw_pripublish') .$where." ORDER BY time DESC";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_pripublish').$where." ORDER BY time DESC",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);

		// $res=pdo_getall('zh_gjw_pripublish',array('state'=>2,'type'=>2,'upfee'=>1,'uniacid'=>$_W['uniacid']), array() , '' , 'topfee DESC' , array());
		if (empty($res)) {
			echo json_encode(array('msg'=>'没有定制商家分类数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res) ; $i++) { 
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$ures[$i]=pdo_get('zh_gjw_register',array('openid'=>$res[$i]['openid']));
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['username']=$ures[$i]['username'];
			}
			echo json_encode(array('msg'=>'定制分类数据','code'=>'200','res'=>$res),320);exit();
		}
	}
	//定制商家分类数据
	public function doPagePriccateid(){
		global $_W, $_GPC;

		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE  uniacid=:uniacid and state=:state and type=:type and c_id=:c_id ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':state']=2;
	    $data[':type']=2;
	    $data[':c_id']=$_GPC['c_id'];
	    $sql="SELECT * FROM ".tablename('zh_gjw_pripublish') .$where." ORDER BY time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_pripublish').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);

		// $res=pdo_getall('zh_gjw_pripublish',array('c_id'=>$_GPC['c_id'],'state'=>2,'type'=>2,'uniacid'=>$_W['uniacid']), array() , '' , 'topfee DESC' , array());
		if (empty($res)) {
			echo json_encode(array('msg'=>'没有定制商家分类数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res) ; $i++) { 
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$ures[$i]=pdo_get('zh_gjw_register',array('openid'=>$res[$i]['openid']));
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['username']=$ures[$i]['username'];
			}
			echo json_encode(array('msg'=>'定制分类数据','code'=>'200','res'=>$res),320);exit();
		}
	}

	//定制用户分类数据推荐
	public function doPagePriuup(){
		global $_W, $_GPC;

		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE  uniacid=:uniacid and state=:state and type=:type and upfee=:upfee ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':state']=2;
	    $data[':type']=1;
	    $data[':upfee']=1;
	    $sql="SELECT * FROM ".tablename('zh_gjw_pripublish') .$where." ORDER BY time DESC";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_pripublish').$where." ORDER BY time DESC",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);

		// $res=pdo_getall('zh_gjw_pripublish',array('state'=>2,'type'=>1,'upfee'=>1,'uniacid'=>$_W['uniacid']), array() , '' , 'topfee DESC' , array());
		if (empty($res)) {
			echo json_encode(array('msg'=>'没有定制用户分类数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res) ; $i++) { 
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$ures[$i]=pdo_get('zh_gjw_register',array('openid'=>$res[$i]['openid']));
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['username']=$ures[$i]['username'];
			}
			echo json_encode(array('msg'=>'定制分类数据','code'=>'200','res'=>$res),320);exit();
		}
	}
	//定制用户分类数据
	public function doPagePriucateid(){
		global $_W, $_GPC;

		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE  uniacid=:uniacid and state=:state and type=:type and c_id=:c_id ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':state']=2;
	    $data[':type']=1;
	    $data[':c_id']=$_GPC['c_id'];
	    $sql="SELECT * FROM ".tablename('zh_gjw_pripublish') .$where." ORDER BY time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_pripublish').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);

		// $res=pdo_getall('zh_gjw_pripublish',array('c_id'=>$_GPC['c_id'],'state'=>2,'type'=>1,'uniacid'=>$_W['uniacid']), array() , '' , 'topfee DESC' , array());
		if (empty($res)) {
			echo json_encode(array('msg'=>'没有定制用户分类数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res) ; $i++) { 
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$ures[$i]=pdo_get('zh_gjw_register',array('openid'=>$res[$i]['openid']));
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['username']=$ures[$i]['username'];
			}
			echo json_encode(array('msg'=>'定制分类数据','code'=>'200','res'=>$res),320);exit();
		}
	}
	//定制置顶
	public function doPagePritoppay(){
		global $_GPC, $_W;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		$root=$_W['siteroot']; 
    	$primoney=pdo_get('zh_gjw_primoney',array('uniacid'=>$_W['uniacid']));
		$total_fee =$primoney['topfee'];
		if($total_fee>0)
		{
			$body = "定制置顶";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
		echo json_encode($return);
	}
	//定制置顶topfee+1
	public function doPagePritopsuccess(){
		global $_W, $_GPC;
		file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=GetGradeprip&m=zh_gjw&order_id=" . $_GPC['id']);//修改等级
		$topfee=pdo_get('zh_gjw_pripublish',array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		$topfee['topfee']=$topfee['topfee']+1;
		$res =	pdo_update('zh_gjw_pripublish', array('topfee' =>$topfee['topfee'],'time'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if ($res) {
			if($_GPC['openid']&&$_GPC['topu']==1){
				$datas['openid']=$_GPC['openid'];
				$datas['type']=18;
				$datas['uniacid']=$_W['uniacid'];
				$datas['number']=1;
				$datas['sjc']=time();
				$datas['time']=date('Y-m-d H:i:s',time());
				pdo_insert('zh_gjw_repucost',$datas);
			}else if($_GPC['openid']&&$_GPC['top']==1){
				$datas['openid']=$_GPC['openid'];
				$datas['type']=16;
				$datas['uniacid']=$_W['uniacid'];
				$datas['number']=1;
				$datas['sjc']=time();
				$datas['time']=date('Y-m-d H:i:s',time());
				pdo_insert('zh_gjw_repucost',$datas);
			}else{
                $primoney=pdo_get('zh_gjw_primoney',array('uniacid'=>$_W['uniacid']));
                $data['p_id']=$_GPC['id'];
                $data['fee']=$primoney['topfee'];
                $data['uniacid']=$_W['uniacid'];
                $data['time']=date('Y-m-d H:i:s',time());
                if ($primoney['topfee']>0) {
                    pdo_insert('zh_gjw_priorder',$data);
                }
            }
			echo json_encode(array('msg'=>'置顶成功','code'=>'200','res'=>$res),320);exit();
		}else{
			echo json_encode(array('msg'=>'置顶失败','code'=>'500'),320);exit();
		}
	}
	//定制推荐
	public function doPagePriuppay(){
		global $_GPC, $_W;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		$root=$_W['siteroot']; 
    	$primoney=pdo_get('zh_gjw_primoney',array('uniacid'=>$_W['uniacid']));
		$total_fee =$primoney['upfee'];
		if($total_fee>0)
		{
			$body = "定制推荐";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
		echo json_encode($return);
	}
	//定制推荐upfee+1
	public function doPagePriupsuccess(){
		global $_W, $_GPC;
		file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=GetGradeprip&m=zh_gjw&order_id=" . $_GPC['id']);//修改等级
		$upfee=pdo_get('zh_gjw_pripublish',array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		$res =	pdo_update('zh_gjw_pripublish', array('upfee' =>1,'time'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if ($res) {
			if($_GPC['openid']&&$_GPC['upu']==1){
				$datas['openid']=$_GPC['openid'];
				$datas['type']=17;
				$datas['uniacid']=$_W['uniacid'];
				$datas['number']=1;
				$datas['sjc']=time();
				$datas['time']=date('Y-m-d H:i:s',time());
				pdo_insert('zh_gjw_repucost',$datas);
			}else if($_GPC['openid']&&$_GPC['up']==1){
				$datas['openid']=$_GPC['openid'];
				$datas['type']=15;
				$datas['uniacid']=$_W['uniacid'];
				$datas['number']=1;
				$datas['sjc']=time();
				$datas['time']=date('Y-m-d H:i:s',time());
				pdo_insert('zh_gjw_repucost',$datas);
			}else{
                $primoney=pdo_get('zh_gjw_primoney',array('uniacid'=>$_W['uniacid']));
                $data['p_id']=$_GPC['id'];
                $data['fee']=$primoney['upfee'];
                $data['uniacid']=$_W['uniacid'];
                $data['time']=date('Y-m-d H:i:s',time());
                if ($primoney['upfee']>0) {
                    pdo_insert('zh_gjw_priorder',$data);
                }
            }
			echo json_encode(array('msg'=>'推荐成功','code'=>'200','res'=>$res),320);exit();
		}else{
			echo json_encode(array('msg'=>'推荐失败','code'=>'500'),320);exit();
		}
	}
	//定制浏览
	public function doPagePriview(){
		global $_GPC, $_W;
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$id=pdo_get('zh_gjw_pripublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if (empty($id['view'])) {
			pdo_update('zh_gjw_pripublish', array('view' =>$user['id']), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
			echo json_encode(array('msg'=>'浏览成功','code'=>'200','res'=>1),320);exit();
		}else{
			$ids=explode(",",$id['view']);
			if (in_array($user['id'], $ids)){
				if (in_array(0,$ids)) {
					$idss=count($ids)-1;
				}else{
					$idss=count($ids);
				}
				echo json_encode(array('msg'=>'浏览过了','code'=>'201','res'=>$idss),320);exit();
			}else{
				array_push($ids,$user['id']);
				$view=implode(',', $ids);
				$res = pdo_update('zh_gjw_pripublish', array('view' =>$view), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
				if (empty($res)) {
					echo json_encode(array('msg'=>'浏览失败','code'=>'500'),320);exit();
				}
				$viewid=pdo_get('zh_gjw_pripublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
				if (in_array(0,explode(",",$viewid['view']))) {
					$viewids=count(explode(",",$viewid['view']))-1;
				}else{
					$viewids=count(explode(",",$viewid['view']));
				}
				echo json_encode(array('msg'=>'浏览成功','code'=>'200','res'=>$viewids),320);exit();
			}
		}
	}
	//定制点赞+1
	public function doPagePriagree(){
		global $_GPC, $_W;
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$id=pdo_get('zh_gjw_pripublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if (empty($id['agree'])) {
			pdo_update('zh_gjw_pripublish', array('agree' =>$user['id']), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
			echo json_encode(array('msg'=>'点赞成功','code'=>'200','res'=>1),320);exit();
		}else{
			$ids=explode(",",$id['agree']);
			if (in_array($user['id'], $ids)){
				if (in_array(0,$ids)) {
					$idss=count($ids)-1;
				}else{
					$idss=count($ids);
				}
				echo json_encode(array('msg'=>'点赞过了','code'=>'201','res'=>$idss),320);exit();
			}else{
				array_push($ids,$user['id']);
				$agree=implode(',', $ids);
				$res = pdo_update('zh_gjw_pripublish', array('agree' =>$agree), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
				if (empty($res)) {
					echo json_encode(array('msg'=>'点赞失败','code'=>'500'),320);exit();
				}
				$agreeid=pdo_get('zh_gjw_pripublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
				if (in_array(0,explode(",",$agreeid['agree']))) {
					$agreeids=count(explode(",",$agreeid['agree']))-1;
				}else{
					$agreeids=count(explode(",",$agreeid['agree']));
				}
				echo json_encode(array('msg'=>'点赞成功','code'=>'200','res'=>$agreeids),320);exit();
			}
		}
	}


	/**
	*定制全部/审
	*/
	public function doPagePriall(){
		global $_GPC, $_W;
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE uniacid=:uniacid and pay=:pay and openid=:openid ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':pay']=2;
		$data[':openid']=$_GPC['openid'];
		$sql="SELECT * FROM ".tablename('zh_gjw_pripublish').$where." ORDER BY time desc";
  		$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_pripublish').$where." ORDER BY time desc",$data);
  		$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		// $shset=pdo_get('zh_gjw_shset',array('uniacid'=>$_W['uniacid']));
		// if ($shset['dbshset']==1) {
		// $res=pdo_getall('zh_gjw_pripublish',array('uniacid'=>$_W['uniacid'],'pay'=>2,'openid'=>$_GPC['openid']));
		// }
		if (empty($res)) {
			echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
		}
			for ($i=0; $i <count($res) ; $i++) { 
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$ures[$i]=pdo_get('zh_gjw_register',array('openid'=>$res[$i]['openid']));
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['username']=$ures[$i]['username'];
			}
		echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res),320);exit();
	}

	/**
	*定制/未审核
	*/
	public function doPagePrinsh(){
		global $_GPC, $_W;
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE uniacid=:uniacid and pay=:pay and openid=:openid and state=:state ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':pay']=2;
		$data[':state']=1;
		$data[':openid']=$_GPC['openid'];
		$sql="SELECT * FROM ".tablename('zh_gjw_pripublish').$where." ORDER BY time desc";
  		$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_pripublish').$where." ORDER BY time desc",$data);
  		$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		// $shset=pdo_get('zh_gjw_shset',array('uniacid'=>$_W['uniacid']));
		// if ($shset['prishset']==1) {
			// $res=pdo_getall('zh_gjw_pripublish',array('state'=>1,'pay'=>2,'uniacid'=>$_W['uniacid'],'openid'=>$_GPC['openid']));
			// $res = pdo_fetchall("SELECT a.*,b.openid,b.phone FROM " . tablename('zh_gjw_dbpublish'). " a"  . " left join " . tablename("zh_gjw_register") . " b on a.phone=b.phone WHERE a.uniacid=:uniacid and b.openid=:openid and a.state=:state ORDER BY a.time desc", array(':uniacid'=>$_W['uniacid'],':openid'=>$_GPC['openid'],':state'=>1));
		// }
		if (empty($res)) {
			echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
		}
			for ($i=0; $i <count($res) ; $i++) { 
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$ures[$i]=pdo_get('zh_gjw_register',array('openid'=>$res[$i]['openid']));
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['username']=$ures[$i]['username'];
			}
		echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res),320);exit();
	}
	/**
	*定制/已审核
	*/
	public function doPagePriysh(){
		global $_GPC, $_W;
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE uniacid=:uniacid and pay=:pay and openid=:openid and state=:state ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':pay']=2;
		$data[':state']=2;
		$data[':openid']=$_GPC['openid'];
		$sql="SELECT * FROM ".tablename('zh_gjw_pripublish').$where." ORDER BY time desc";
  		$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_pripublish').$where." ORDER BY time desc",$data);
  		$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		// $shset=pdo_get('zh_gjw_shset',array('uniacid'=>$_W['uniacid']));
		// if ($shset['prishset']==1) {
			// $res=pdo_getall('zh_gjw_pripublish',array('state'=>2,'pay'=>2,'uniacid'=>$_W['uniacid'],'openid'=>$_GPC['openid']));
		// }
		if (empty($res)) {
			echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
		}
			for ($i=0; $i <count($res) ; $i++) { 
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$ures[$i]=pdo_get('zh_gjw_register',array('openid'=>$res[$i]['openid']));
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['username']=$ures[$i]['username'];
			}
		echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res),320);exit();
	}
	/**
	*定制/已拒审核
	*/
	public function doPagePrijsh(){
		global $_GPC, $_W;
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE uniacid=:uniacid and pay=:pay and openid=:openid and state=:state ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':pay']=2;
		$data[':state']=3;
		$data[':openid']=$_GPC['openid'];
		$sql="SELECT * FROM ".tablename('zh_gjw_pripublish').$where." ORDER BY time desc";
  		$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_pripublish').$where." ORDER BY time desc",$data);
  		$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		// $shset=pdo_get('zh_gjw_shset',array('uniacid'=>$_W['uniacid']));
		// if ($shset['prishset']==1) {
		// 	$res=pdo_getall('zh_gjw_pripublish',array('state'=>3,'pay'=>2,'uniacid'=>$_W['uniacid'],'openid'=>$_GPC['openid']));
		// }
		if (empty($res)) {
			echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
		}
			for ($i=0; $i <count($res) ; $i++) { 
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$ures[$i]=pdo_get('zh_gjw_register',array('openid'=>$res[$i]['openid']));
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['username']=$ures[$i]['username'];
			}
		echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res),320);exit();
	}
	//定制删除
    public function doPagePridelete(){
    	global $_GPC,$_W;
    	$res=pdo_delete('zh_gjw_pripublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if ($res) {
		echo json_encode(array('msg'=>'删除成功','code'=>'200'),320);exit();
		}
		echo json_encode(array('msg'=>'删除失败','code'=>'500'),320);exit();

    }

	//定制查看允许
	public function doPageLookpro(){
		global $_GPC, $_W;
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$id=pdo_get('zh_gjw_pripublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		$ids=explode(",",$id['lookpro']);
		if (in_array($user['id'], $ids)){
			if (in_array($user['id'],$ids)) {
				echo json_encode(array('msg'=>'支付过了','code'=>'200'),320);exit();
			}else{
				echo json_encode(array('msg'=>'未支付','code'=>'500'),320);exit();
			}
		}
		echo json_encode(array('msg'=>'未支付','code'=>'500'),320);exit();
	}
	//看帖费
	public function doPageLookfee(){
		global $_GPC, $_W;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		$root=$_W['siteroot']; 
		$total_fee =$_GPC['lookfee'];
		if($total_fee>0)
		{
			$body = "看帖费";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
		echo json_encode($return);
	}
	//看帖支付成功改变状态
	public function doPageLookpaysuccess(){
		global $_W, $_GPC;
      	//file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=GetGradelook&m=zh_gjw&order_id=" . $_GPC['openid']);//修改等级
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$id=pdo_get('zh_gjw_pripublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if (empty($id['lookpro'])) {
			$res = pdo_update('zh_gjw_pripublish', array('lookpro' =>$user['id']), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
			if ($res) {
	    		$primoney=pdo_get('zh_gjw_primoney',array('uniacid'=>$_W['uniacid']));
				$data['u_id']=$user['id'];
				$data['fee']=$primoney['lookfee'];
				$data['uniacid']=$_W['uniacid'];
				$data['time']=date('Y-m-d H:i:s',time());
				if ($primoney['lookfee']>0) {
					pdo_insert('zh_gjw_prilookorder',$data);
				}
				echo json_encode(array('msg'=>'成功','code'=>'200'),320);exit();
			}else{
				echo json_encode(array('msg'=>'失败','code'=>'500'),320);exit();
			}
		}
		$ids=explode(",",$id['lookpro']);
		array_push($ids,$user['id']);
		$lookpro=implode(',', $ids);
		$res = pdo_update('zh_gjw_pripublish', array('lookpro' =>$lookpro), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if ($res) {
	    		$primoney=pdo_get('zh_gjw_primoney',array('uniacid'=>$_W['uniacid']));
				$data['u_id']=$user['id'];
				$data['fee']=$primoney['lookfee'];
				$data['uniacid']=$_W['uniacid'];
				$data['time']=date('Y-m-d H:i:s',time());
				if ($primoney['lookfee']>0) {
					pdo_insert('zh_gjw_prilookorder',$data);
				}
			echo json_encode(array('msg'=>'成功','code'=>'200'),320);exit();
		}else{
			echo json_encode(array('msg'=>'失败','code'=>'500'),320);exit();
		}
	}
	//帖子详情
	public function doPagePridetail(){
		global $_W, $_GPC;
		$res=pdo_get('zh_gjw_pripublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if ($res) {
			$user=pdo_get('zh_gjw_register',array('openid'=>$res['openid'],'uniacid'=>$_W['uniacid']));
			$res['avatar']=$user['avatar'];
			$res['username']=$user['username'];
			$res['view']=count(explode(',',$res['view']));
			echo json_encode(array('msg'=>'成功','code'=>'200','res'=>$res),320);exit();
		}else{
			echo json_encode(array('msg'=>'失败','code'=>'500'),320);exit();
		}
	}
	//定制商家店铺分类数据推荐
	public function doPagePricusup(){
		global $_W, $_GPC;

		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE  uniacid=:uniacid and sh=:sh and type=:type and upfee=:upfee ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':sh']=2;
	    $data[':type']=1;
	    $data[':upfee']=1;
	    $sql="SELECT * FROM ".tablename('zh_gjw_cusmanage') .$where." ORDER BY time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_cusmanage').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);

		// $res=pdo_getall('zh_gjw_cusmanage',array('sh'=>2,'upfee'=>1,'type'=>1,'uniacid'=>$_W['uniacid']), array() , '' , 'topfee DESC' , array());
		if (empty($res)) {
			echo json_encode(array('msg'=>'没有商家店铺分类数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res) ; $i++) { 
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$res[$i]['password']='******';
				$ures[$i]=pdo_get('zh_gjw_register',array('openid'=>$res[$i]['openid']));//?
			}
			echo json_encode(array('msg'=>'定制商家店铺推荐数据','code'=>'200','res'=>$res),320);exit();
		}
	}
	//定制商家店铺分类数据
	public function doPagePricuscateid(){
		global $_W, $_GPC;

		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE  uniacid=:uniacid and sh=:sh and type=:type and shot_id=:shot_id ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':sh']=2;
	    $data[':type']=1;
	    $data[':shot_id']=$_GPC['shot_id'];
	    $sql="SELECT * FROM ".tablename('zh_gjw_cusmanage') .$where." ORDER BY time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_cusmanage').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);

		// $res=pdo_getall('zh_gjw_cusmanage',array('shot_id'=>$_GPC['shot_id'],'sh'=>2,'type'=>1,'uniacid'=>$_W['uniacid']), array() , '' , 'topfee DESC' , array());
		if (empty($res)) {
			echo json_encode(array('msg'=>'没有定制商家店铺分类数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res) ; $i++) { 
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$res[$i]['password']='******';
				$ures[$i]=pdo_get('zh_gjw_register',array('openid'=>$res[$i]['openid']));//?
			}
			echo json_encode(array('msg'=>'定制商家店铺分类数据','code'=>'200','res'=>$res),320);exit();
		}
	}
	//商家个人资料
	public function doPageCusperson(){
		global $_W,$_GPC;
      	if($_GPC['admin']){
			$res=pdo_get('zh_gjw_cusmanage',array('phone'=>$_GPC['admin']));
        }else{
			$res=pdo_get('zh_gjw_cusmanage',array('openid'=>$_GPC['openid']));
        }
		if (empty($res)) {
			echo json_encode(array('msg'=>'没有数据','code'=>'500'),320);exit();
		}else{
			echo json_encode(array('msg'=>'呵呵','code'=>'200','res'=>$res),320);exit();
		}
	}
	//地摊费用
    public function doPageMarketmoney(){
    	global $_GPC,$_W;
    	$marketmoney=pdo_get('zh_gjw_marketmoney',array('uniacid'=>$_W['uniacid']));
    	if (empty($marketmoney)) {
    		echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
    	}elseif($marketmoney){
    		echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$marketmoney),320);exit();
    	}
    }
    //发布地摊
    public function doPageMarketpublish(){
    	global $_GPC,$_W;
		$data['formid']=$_GPC['formid'];
		$data['title']=$_GPC['title'];
		$data['phone']=$_GPC['admin'];
		$data['fmoney']=$_GPC['fmoney'];
		$data['lmoney']=$_GPC['lmoney'];
		$data['userbzj']=$_GPC['userbzj'];
		$data['bzj']=$_GPC['bzj'];
		$data['co_id']=$_GPC['co_id'];
		$data['ct_id']=$_GPC['ct_id'];
		$data['cth_id']=$_GPC['cth_id'];
		$data['fromtime']=$_GPC['fromtime'];
		$data['totime']=$_GPC['totime'];
		$data['exfee']=$_GPC['exfee'];
		$data['detail']=$_GPC['detail'];
		$data['img']=$_GPC['img'];
		$data['video']=$_GPC['videoimgtemp'];
		$data['state']=1;
		$data['uniacid']=$_W['uniacid'];
		$data['time']=date('Y-m-d H:i:s',time());
		$res=pdo_insert('zh_gjw_marketpublish',$data);
		$res_id=pdo_insertid();
    	if ($res) {
    		echo json_encode(array('msg'=>'记录成功','code'=>'200','res'=>$res,'res_id'=>$res_id),320);exit();
		}else{
			echo json_encode(array('msg'=>'记录失败','code'=>'500'),320);exit();
		}
    }
    //地摊发布支付
	public function doPageMarketpay(){
		global $_W, $_GPC;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$res_fee=0;
    	$shset=pdo_get('zh_gjw_shset',array('uniacid'=>$_W['uniacid']));
    	if ($shset['marketshset']==1) {
	    	if ($_GPC['upstate']==1) {
	    		if($_GPC['publishfee']>0){
	    			// $res_fee=$_GPC['publishfee']+$_GPC['bzj']+$_GPC['upfee'];
	    			$res_fee=$_GPC['publishfee']+$_GPC['upfee'];
	    		}else{
	    			// $res_fee=$_GPC['bzj']+$_GPC['upfee'];
	    			$res_fee=$_GPC['upfee'];
	    		}
			}else{
				if($_GPC['publishfee']>0){
	    			// $res_fee=$_GPC['publishfee']+$_GPC['bzj'];
	    			$res_fee=$_GPC['publishfee'];
	    		}else{
	    			// $res_fee=$_GPC['bzj'];
	    			$res_fee=0;
	    		}
			}
    	}elseif ($shset['marketshset']!=1) {
    		if ($_GPC['upstate']==1) {
	    		if($_GPC['publishfee']>0){
	    			// $res_fee=$_GPC['publishfee']+$_GPC['bzj']+$_GPC['upfee'];
	    			$res_fee=$_GPC['publishfee']+$_GPC['upfee'];
	    		}else{
	    			// $res_fee=$_GPC['bzj']+$_GPC['upfee'];
	    			$res_fee=$_GPC['upfee'];
	    		}
			}else{
				if($_GPC['publishfee']>0){
	    			// $res_fee=$_GPC['publishfee']+$_GPC['bzj'];
	    			$res_fee=$_GPC['publishfee'];
	    		}else{
	    			// $res_fee=$_GPC['bzj'];
	    			$res_fee=0;
	    		}
			}
    	}
		// if ($_GPC['topstate']==1) {
		// 	$res_fee=$res_fee+$_GPC['topfee'];
		// }
      	if ($_GPC['alltype']==12) {
			$res_fee=$res_fee-$_GPC['upfee'];
		}
		if ($_GPC['alltype']==16) {
			$res_fee=$res_fee-$_GPC['publishfee'];
		}
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		pdo_update('zh_gjw_marketpublish', array('paycode' =>$out_trade_no), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		$root=$_W['siteroot']; 
		$total_fee =$res_fee;
		if($total_fee>0)
		{
			$body = "地摊发布";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
		echo json_encode($return);
	}
	//地摊发布支付成功改变state
	public function doPageMarketsuccess(){
		global $_W, $_GPC;
		file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=GetGrademarketp&m=zh_gjw&order_id=" . $_GPC['res_id']);//修改等级
		/*function getaccess_token($_W){
          $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
          $appid=$res['appid'];
          $secret=$res['appsecret'];
          $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL,$url);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
          $data = curl_exec($ch);
          curl_close($ch);
          $data = json_decode($data,true);
          return $data['access_token'];
        }*/
        function set_msg($_W,$id){
            //$access_token = getaccess_token($_W);
            $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
            $openid=pdo_get('zh_gjw_marketpublish',array('id'=>$id));
            $register=pdo_get('zh_gjw_register',array('phone'=>$openid['phone']));
            $formwork ='{
                "touser": "'.$register["openid"].'",
                "template_id": "'.$ress["templeid"].'",
                "form_id":"'.$openid['formid'].'",
                "data": {
                    "keyword1": {
                        "value": "'.$openid['title'].'",
                        "color": "#173177"
                    },
                    "keyword2": {
                        "value":"地摊审核通过",
                        "color": "#173177"
                    }
                }  
            }';
            $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL,$url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
            curl_setopt($ch, CURLOPT_POST,1);
            curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
            $data = curl_exec($ch);
            curl_close($ch);
           return $data;
        }
    	$shset=pdo_get('zh_gjw_shset',array('uniacid'=>$_W['uniacid']));
    	$marketmoney=pdo_get('zh_gjw_marketmoney',array('uniacid'=>$_W['uniacid']));
    	$marketpublish=pdo_get('zh_gjw_marketpublish',array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
    	/*if ($shset['marketshset']==1) {
			if ($_GPC['upstate']==1) {
				if ($marketmoney['publishfee']>0) {
					$allmoney=$marketmoney['publishfee']+$marketmoney['upfee']+$marketpublish['bzj'];
					pdo_update('zh_gjw_marketpublish', array('pay' => 1,'upfee' =>1,'payfee'=>$allmoney,'uptime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//有发布费、有推荐、审核开启
				}else{
					$allmoney=$marketmoney['upfee']+$marketpublish['bzj'];
					pdo_update('zh_gjw_marketpublish', array('pay' => 1,'upfee' =>1,'payfee'=>$allmoney,'uptime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//无发布费、有推荐、审核开启
				}
			}
			if($_GPC['upstate']!=1){
				if ($marketmoney['publishfee']>0) {
					$allmoney=$marketmoney['publishfee']+$marketpublish['bzj'];
					pdo_update('zh_gjw_marketpublish', array('pay' => 1,'payfee'=>$allmoney), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//有发布费、无推荐、审核开启
				}else{
					pdo_update('zh_gjw_marketpublish', array('pay' => 1,'payfee'=>$marketpublish['bzj']), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//无发布费、无推荐、审核开启
				}
			}
			echo json_encode(array('msg'=>'微拍发布改变状态成功','code'=>'200','res'=>$res),320);exit();
		}elseif ($shset['marketshset']!=1) {
			if ($_GPC['upstate']==1) {
				if ($marketmoney['publishfee']>0) {
					$allmoney=$marketmoney['publishfee']+$marketmoney['upfee']+$marketpublish['bzj'];
					pdo_update('zh_gjw_marketpublish', array('pay' => 1,'upfee' =>1,'payfee'=>$allmoney,'state' => 2,'shtime'=>date('Y-m-d H:i:s',time()),'uptime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//有发布费、有推荐、审核关闭
				}else{
					$allmoney=$marketmoney['upfee']+$marketpublish['bzj'];
					pdo_update('zh_gjw_marketpublish', array('pay' => 1,'upfee' =>1,'payfee'=>$allmoney,'state' => 2,'shtime'=>date('Y-m-d H:i:s',time()),'uptime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//无发布费、有推荐、审核关闭
				}
			}
			if($_GPC['upstate']!=1){
				if ($marketmoney['publishfee']>0) {
					$allmoney=$marketmoney['publishfee']+$marketpublish['bzj'];
					pdo_update('zh_gjw_marketpublish', array('pay' => 1,'payfee'=>$allmoney,'state' => 2,'shtime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//有发布费、无推荐、审核关闭
				}else{
					pdo_update('zh_gjw_marketpublish', array('pay' => 1,'state' => 2,'payfee'=>$marketpublish['bzj'],'shtime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//无发布费、无推荐、审核关闭
				}
			}
			set_msg($_W,$_GPC['res_id']);
			echo json_encode(array('msg'=>'微拍发布改变状态成功','code'=>'200','res'=>$res),320);exit();
		}*/
      	if ($shset['marketshset']==1) {
			if ($_GPC['upstate']==1) {
				if ($marketmoney['publishfee']>0) {
					$allmoney=$marketmoney['publishfee']+$marketmoney['upfee'];
					if ($_GPC['alltype']==12) {
						pdo_update('zh_gjw_marketpublish', array('type' => 12,'pay' => 1,'upfee' =>1,'payfee'=>$marketmoney['publishfee']), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=11;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==16) {
						pdo_update('zh_gjw_marketpublish', array('type' => 16,'pay' => 1,'upfee' =>1,'payfee'=>$marketmoney['upfee']), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=3;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==20) {
						pdo_update('zh_gjw_dbpublish', array('type' => 20,'pay' => 1,'upfee' =>1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=3;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
						$datas['openid']=$_GPC['openid'];
						$datas['type']=11;
						$datas['uniacid']=$_W['uniacid'];
						$datas['number']=1;
						$datas['sjc']=time();
						$datas['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$datas);
					}
					pdo_update('zh_gjw_marketpublish', array('type'=>$_GPC['alltype'],'pay' => 1,'upfee' =>1,'payfee'=>$allmoney,'uptime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//有发布费、有推荐、审核开启
				}else{
					if ($_GPC['alltype']==10) {
						pdo_update('zh_gjw_marketpublish', array('type' => 10,'pay' => 1,'upfee' =>1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=11;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==18) {
						pdo_update('zh_gjw_marketpublish', array('type' => 18,'pay' => 1,'upfee' =>1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=11;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					pdo_update('zh_gjw_marketpublish', array('type'=>$_GPC['alltype'],'pay' => 1,'upfee' =>1,'payfee'=>$marketmoney['upfee'],'uptime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//无发布费、有推荐、审核开启
				}
			}
			if($_GPC['upstate']!=1){
				if ($marketmoney['publishfee']>0) {
					if ($_GPC['alltype']==15) {
						pdo_update('zh_gjw_marketpublish', array('type' => 15,'pay' => 1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=3;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==19) {
						pdo_update('zh_gjw_marketpublish', array('type' => 19,'pay' => 1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=3;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					pdo_update('zh_gjw_marketpublish', array('type'=>$_GPC['alltype'],'pay' => 1,'payfee'=>$marketmoney['publishfee']), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//有发布费、无推荐、审核开启
				}else{
					pdo_update('zh_gjw_marketpublish', array('type'=>$_GPC['alltype'],'pay' => 1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//无发布费、无推荐、审核开启
				}
			}
			echo json_encode(array('msg'=>'地摊发布改变状态成功','code'=>'200','res'=>$res),320);exit();
		}elseif ($shset['marketshset']!=1) {
			if ($_GPC['upstate']==1) {
				if ($marketmoney['publishfee']>0) {
					$allmoney=$marketmoney['publishfee']+$marketmoney['upfee'];
					if ($_GPC['alltype']==12) {
						pdo_update('zh_gjw_marketpublish', array('type' => 12,'pay' => 1,'upfee' =>1,'payfee'=>$marketmoney['publishfee'],'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=11;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==16) {
						pdo_update('zh_gjw_marketpublish', array('type' => 16,'pay' => 1,'upfee' =>1,'payfee'=>$marketmoney['upfee'],'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=3;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==20) {
						pdo_update('zh_gjw_dbpublish', array('type' => 20,'pay' => 1,'upfee' =>1,'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=3;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
						$datas['openid']=$_GPC['openid'];
						$datas['type']=11;
						$datas['uniacid']=$_W['uniacid'];
						$datas['number']=1;
						$datas['sjc']=time();
						$datas['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$datas);
					}
					pdo_update('zh_gjw_marketpublish', array('type'=>$_GPC['alltype'],'pay' => 1,'upfee' =>1,'payfee'=>$allmoney,'state' => 2,'shtime'=>date('Y-m-d H:i:s',time()),'uptime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//有发布费、有推荐、审核关闭
				}else{
					if ($_GPC['alltype']==10) {
						pdo_update('zh_gjw_marketpublish', array('type' => 10,'pay' => 1,'upfee' =>1,'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=11;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==18) {
						pdo_update('zh_gjw_marketpublish', array('type' => 18,'pay' => 1,'upfee' =>1,'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=11;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					pdo_update('zh_gjw_marketpublish', array('type'=>$_GPC['alltype'],'pay' => 1,'upfee' =>1,'payfee'=>$marketmoney['upfee'],'state' => 2,'shtime'=>date('Y-m-d H:i:s',time()),'uptime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//无发布费、有推荐、审核关闭
				}
			}
			if($_GPC['upstate']!=1){
				if ($marketmoney['publishfee']>0) {
					if ($_GPC['alltype']==15) {
						pdo_update('zh_gjw_marketpublish', array('type' => 15,'pay' => 1,'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=3;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==19) {
						pdo_update('zh_gjw_marketpublish', array('type' => 19,'pay' => 1,'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=3;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					pdo_update('zh_gjw_marketpublish', array('type'=>$_GPC['alltype'],'pay' => 1,'payfee'=>$marketmoney['publishfee'],'state' => 2,'shtime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//有发布费、无推荐、审核关闭
				}else{
					pdo_update('zh_gjw_marketpublish', array('type'=>$_GPC['alltype'],'pay' => 1,'state' => 2,'shtime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//无发布费、无推荐、审核关闭
				}
			}
			set_msg($_W,$_GPC['res_id']);
			echo json_encode(array('msg'=>'地摊发布改变状态成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'地摊发布改变状态出错','code'=>'500','res'=>$res),320);exit();
  		//$shset=pdo_get('zh_gjw_shset',array('uniacid'=>$_W['uniacid']));
		// if ($_GPC['upstate']==1) {
		// 	pdo_update('zh_gjw_marketpublish', array('upfee' => 1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		// }
		// if ($_GPC['topstate']==1) {
		// 	pdo_update('zh_gjw_marketpublish', array('topfee' => 1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		// }
		// if ($shset['marketshset']==1) {
		// 	$res = pdo_update('zh_gjw_marketpublish', array('pay' => 1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		// 	echo json_encode(array('msg'=>'嗨','code'=>'200','res'=>$res),320);exit();
		// }elseif ($shset['marketshset']==0||$shset['marketshset']==null) {
		// 	$res = pdo_update('zh_gjw_marketpublish', array('pay' => 1,'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		// 	echo json_encode(array('msg'=>'嗨','code'=>'200','res'=>$res),320);exit();
		// }
	}
  
	//地摊全部数据
	public function doPageMarketcus(){
		global $_W, $_GPC;
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=6;
		$where=' WHERE  uniacid=:uniacid and state=:state ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':state']=2;
	    //$where.=" and totime >=FROM_UNIXTIME(".time().") and fromtime<=FROM_UNIXTIME(".time().")";
      	$where.=" and time+INTERVAL 120 HOUR>NOW() and NOW()>time";
	    $sql="SELECT * FROM ".tablename('zh_gjw_marketpublish') .$where." ORDER BY time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_marketpublish').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		if (empty($res)) {
			echo json_encode(array('msg'=>'没有地摊分类数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res) ; $i++) { 
				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$ures[$i]=pdo_get('zh_gjw_register',array('phone'=>$res[$i]['phone']));//?
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['username']=$ures[$i]['username'];
				$resu=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['reputation']=$resu['reputation'];
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['level_name']=$resu['level_name'];
				$res[$i]['cusname']=$resu['cusname'];
				$res[$i]['storeimg']=$resu['storeimg'];

				$shot=pdo_getall('zh_gjw_marketbuy',array('market_id'=>$res[$i]['id'],'uniacid'=>$_W['uniacid']), array() , '' , 'fee DESC' , array());
				if ($shot) {
					$res[$i]['newfee']=$shot[0]['fee'];
				}else{
					$res[$i]['newfee']=0;
				}
				$res[$i]['totimesjc']=strtotime($res[$i]['totime']);
			}
			if (empty($res)) {
				echo json_encode(array('msg'=>'地摊推荐数据','code'=>'500'),320);exit();
			}
			echo json_encode(array('msg'=>'地摊推荐数据','code'=>'200','res'=>$res),320);exit();
		}
	}
	//地摊分类数据推荐
	public function doPageMarketcusup(){
		global $_W, $_GPC;
		// $arr=array();
		// $res=pdo_getall('zh_gjw_marketpublish',array('state'=>2,'upfee'=>1,'uniacid'=>$_W['uniacid']), array() , '' , 'topfee DESC' , array());

		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=6;
		$where=' WHERE  uniacid=:uniacid and state=:state and upfee=:upfee ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':state']=2;
	    $data[':upfee']=1;
	    //$where.=" and totime >=FROM_UNIXTIME(".time().") and fromtime<=FROM_UNIXTIME(".time().")";
	    //$where.=" and shtime+INTERVAL 120 HOUR>NOW() and NOW()>shtime";
	    $where.=" and time+INTERVAL 120 HOUR>NOW() and NOW()>time";
	    $sql="SELECT * FROM ".tablename('zh_gjw_marketpublish') .$where." ORDER BY uptime desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_marketpublish').$where." ORDER BY uptime desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);


		if (empty($res)) {
			echo json_encode(array('msg'=>'没有地摊分类数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res) ; $i++) { 
				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$ures[$i]=pdo_get('zh_gjw_register',array('phone'=>$res[$i]['phone']));//?
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['ulevel_name']=$ures[$i]['level_name'];
				$res[$i]['username']=$ures[$i]['username'];
				$resu=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['reputation']=$resu['reputation'];
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['cusname']=$resu['cusname'];
				$res[$i]['level_name']=$resu['level_name'];
				$res[$i]['storeimg']=$resu['storeimg'];

				$shot=pdo_getall('zh_gjw_marketbuy',array('market_id'=>$res[$i]['id'],'uniacid'=>$_W['uniacid']), array() , '' , 'fee DESC' , array());
				if ($shot) {
					$res[$i]['newfee']=$shot[0]['fee'];
				}else{
					$res[$i]['newfee']=0;
				}
				$res[$i]['totimesjc']=strtotime($res[$i]['time'])+86400*5;
			}
			// for ($j=0; $j <count($res) ; $j++) { 
			// 	if (strtotime($res[$j]['totime'])>time() && time()>strtotime($res[$j]['fromtime'])) {
			// 		$res[$j]['totimesjc']=strtotime($res[$j]['totime']);
			// 		array_push($arr,$res[$j]);
			// 	}
			// }
			if (empty($res)) {
				echo json_encode(array('msg'=>'地摊推荐数据','code'=>'500'),320);exit();
			}
			echo json_encode(array('msg'=>'地摊推荐数据','code'=>'200','res'=>$res),320);exit();
		}
	}
	//地摊分类数据
	public function doPageMarketcuscateid(){
		global $_W, $_GPC;
		// $arr=array();
		// $res=pdo_getall('zh_gjw_marketpublish',array('cth_id'=>$_GPC['cth_id'],'state'=>2,'uniacid'=>$_W['uniacid']), array() , '' , 'topfee DESC' , array());

		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE  uniacid=:uniacid and state=:state and cth_id=:cth_id ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':state']=2;
	    $data[':cth_id']=$_GPC['cth_id'];
	    // // $where.=" and NOW()<fromtime and fromtime<NOW()+INTERVAL 48 HOUR";
	    //$where.=" and totime >=FROM_UNIXTIME(".time().") and fromtime<=FROM_UNIXTIME(".time().")";
	    //$where.=" and shtime+INTERVAL 120 HOUR>NOW() and NOW()>shtime";
	    $where.=" and time+INTERVAL 120 HOUR>NOW() and NOW()>time";
	    $sql="SELECT * FROM ".tablename('zh_gjw_marketpublish') .$where." ORDER BY time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_marketpublish').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);

		if (empty($res)) {
			echo json_encode(array('msg'=>'没有地摊分类数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res) ; $i++) { 
				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$ures[$i]=pdo_get('zh_gjw_register',array('phone'=>$res[$i]['phone']));//?
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['ulevel_name']=$ures[$i]['level_name'];
				$res[$i]['username']=$ures[$i]['username'];
				$resu=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['reputation']=$resu['reputation'];
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['cusname']=$resu['cusname'];
				$res[$i]['level_name']=$resu['level_name'];
				$res[$i]['storeimg']=$resu['storeimg'];

				 $res[$i]['totimesjc']=strtotime($res[$i]['time'])+86400*5;
			}
			// for ($j=0; $j <count($res) ; $j++) { 
			// 	if (0<strtotime($res[$j]['fromtime'])-time() && strtotime($res[$j]['fromtime'])-time()<86400) {
			// 		$res[$j]['totimesjc']=strtotime($res[$j]['totime']);
			// 		array_push($arr,$res[$j]);
			// 	}
			// }
			if (empty($res)) {
				echo json_encode(array('msg'=>'地摊分类数据','code'=>'500'),320);exit();
			}
			echo json_encode(array('msg'=>'地摊分类数据','code'=>'200','res'=>$res),320);exit();
		}
	}
  	//地摊分类二级数据
	public function doPageMarketsub(){
		global $_W, $_GPC;
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE  uniacid=:uniacid and state=:state and ct_id=:ct_id ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':state']=2;
	    $data[':ct_id']=$_GPC['ct_id'];
	    //$where.=" and totime >=FROM_UNIXTIME(".time().") and fromtime<=FROM_UNIXTIME(".time().")";
	    //$where.=" and shtime+INTERVAL 120 HOUR>NOW() and NOW()>shtime";
	    $where.=" and time+INTERVAL 120 HOUR>NOW() and NOW()>time";
	    $sql="SELECT * FROM ".tablename('zh_gjw_marketpublish') .$where." ORDER BY time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_marketpublish').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		if (empty($res)) {
			echo json_encode(array('msg'=>'没有地摊分类数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res) ; $i++) { 
				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$ures[$i]=pdo_get('zh_gjw_register',array('phone'=>$res[$i]['phone']));//?
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['ulevel_name']=$ures[$i]['level_name'];
				$res[$i]['username']=$ures[$i]['username'];
				$resu=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['reputation']=$resu['reputation'];
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['cusname']=$resu['cusname'];
				$res[$i]['level_name']=$resu['level_name'];
				$res[$i]['storeimg']=$resu['storeimg'];

				$shot=pdo_getall('zh_gjw_marketbuy',array('market_id'=>$res[$i]['id'],'uniacid'=>$_W['uniacid']), array() , '' , 'fee DESC' , array());
				if ($shot) {
					$res[$i]['newfee']=$shot[0]['fee'];
				}else{
					$res[$i]['newfee']=0;
				}
				$res[$i]['totimesjc']=strtotime($res[$i]['time'])+86400*5;

			}
			if (empty($res)) {
				echo json_encode(array('msg'=>'地摊推荐数据','code'=>'500'),320);exit();
			}
			echo json_encode(array('msg'=>'地摊推荐数据','code'=>'200','res'=>$res),320);exit();
		}
	}
	//地摊分类二级推荐数据
	public function doPageMarketsubup(){
		global $_W, $_GPC;
		// $arr=array();
		// $res=pdo_getall('zh_gjw_marketpublish',array('ct_id'=>$_GPC['ct_id'],'state'=>2,'upfee'=>1,'uniacid'=>$_W['uniacid']), array() , '' , 'topfee DESC' , array());

		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE  uniacid=:uniacid and state=:state and upfee=:upfee and ct_id=:ct_id ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':state']=2;
	    $data[':upfee']=1;
	    $data[':ct_id']=$_GPC['ct_id'];
	    // // $where.=" and NOW()<fromtime and fromtime<NOW()+INTERVAL 48 HOUR";
	    //$where.=" and totime >=FROM_UNIXTIME(".time().") and fromtime<=FROM_UNIXTIME(".time().")";
	    //$where.=" and shtime+INTERVAL 120 HOUR>NOW() and NOW()>shtime";
	    $where.=" and time+INTERVAL 120 HOUR>NOW() and NOW()>time";
	    $sql="SELECT * FROM ".tablename('zh_gjw_marketpublish') .$where." ORDER BY uptime desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_marketpublish').$where." ORDER BY uptime desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);

		if (empty($res)) {
			echo json_encode(array('msg'=>'没有地摊分类数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res) ; $i++) { 
				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$ures[$i]=pdo_get('zh_gjw_register',array('phone'=>$res[$i]['phone']));//?
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['ulevel_name']=$ures[$i]['level_name'];
				$res[$i]['username']=$ures[$i]['username'];
				$resu=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone']));
				$res[$i]['cusname']=$resu['cusname'];
				$res[$i]['level_name']=$resu['level_name'];
				$res[$i]['storeimg']=$resu['storeimg'];

				$shot=pdo_getall('zh_gjw_marketbuy',array('market_id'=>$res[$i]['id'],'uniacid'=>$_W['uniacid']), array() , '' , 'fee DESC' , array());
				if ($shot) {
					$res[$i]['newfee']=$shot[0]['fee'];
				}else{
					$res[$i]['newfee']=0;
				}
				$res[$i]['totimesjc']=strtotime($res[$i]['time'])+86400*5;

			}
			// for ($j=0; $j <count($res) ; $j++) { 
			// 	if (strtotime($res[$j]['totime'])>time() && time()>strtotime($res[$j]['fromtime'])) {
			// 		$res[$j]['totimesjc']=strtotime($res[$j]['totime']);
			// 		array_push($arr,$res[$j]);
			// 	}
			// }
			if (empty($res)) {
				echo json_encode(array('msg'=>'地摊推荐数据','code'=>'500'),320);exit();
			}
			echo json_encode(array('msg'=>'地摊推荐数据','code'=>'200','res'=>$res),320);exit();
		}
	}
	//地摊浏览+1
	public function doPageMarketview(){
		global $_GPC, $_W;
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$id=pdo_get('zh_gjw_marketpublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if (empty($id['view'])) {
			pdo_update('zh_gjw_marketpublish', array('view' =>$user['id']), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
			echo json_encode(array('msg'=>'浏览成功','code'=>'200','res'=>1),320);exit();
		}else{
			$ids=explode(",",$id['view']);
			if (in_array($user['id'], $ids)){
				if (in_array(0,$ids)) {
					$idss=count($ids)-1;
				}else{
					$idss=count($ids);
				}
				echo json_encode(array('msg'=>'浏览过了','code'=>'201','res'=>$idss),320);exit();
			}else{
				array_push($ids,$user['id']);
				$view=implode(',', $ids);
				$res = pdo_update('zh_gjw_marketpublish', array('view' =>$view), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
				if (empty($res)) {
					echo json_encode(array('msg'=>'浏览失败','code'=>'500'),320);exit();
				}
				$viewid=pdo_get('zh_gjw_marketpublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
				if (in_array(0,explode(",",$viewid['view']))) {
					$viewids=count(explode(",",$viewid['view']))-1;
				}else{
					$viewids=count(explode(",",$viewid['view']));
				}
				echo json_encode(array('msg'=>'浏览成功','code'=>'200','res'=>$viewids),320);exit();
			}
		}
	}
	//地摊点赞+1
	public function doPageMarketagree(){
		global $_GPC, $_W;
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$id=pdo_get('zh_gjw_marketpublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if (empty($id['agree'])) {
			pdo_update('zh_gjw_marketpublish', array('agree' =>$user['id']), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
			echo json_encode(array('msg'=>'点赞成功','code'=>'200','res'=>1),320);exit();
		}else{
			$ids=explode(",",$id['agree']);
			if (in_array($user['id'], $ids)){
				if (in_array(0,$ids)) {
					$idss=count($ids)-1;
				}else{
					$idss=count($ids);
				}
				echo json_encode(array('msg'=>'点赞过了','code'=>'201','res'=>$idss),320);exit();
			}else{
				array_push($ids,$user['id']);
				$agree=implode(',', $ids);
				$res = pdo_update('zh_gjw_marketpublish', array('agree' =>$agree), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
				if (empty($res)) {
					echo json_encode(array('msg'=>'点赞失败','code'=>'500'),320);exit();
				}
				$agreeid=pdo_get('zh_gjw_marketpublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
				if (in_array(0,explode(",",$agreeid['agree']))) {
					$agreeids=count(explode(",",$agreeid['agree']))-1;
				}else{
					$agreeids=count(explode(",",$agreeid['agree']));
				}
				echo json_encode(array('msg'=>'点赞成功','code'=>'200','res'=>$agreeids),320);exit();
			}
		}
	}
	//地摊详情点赞没有
	public function doPageMarketagreedetail(){
		global $_W, $_GPC;
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$id=pdo_get('zh_gjw_marketpublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		// if (!empty($id)) {
			$ids=explode(",",$id['agree']);
			if (in_array($user['id'], $ids)){
					echo json_encode(array('msg'=>'点赞过了','code'=>'200'),320);exit();
			}else{
				echo json_encode(array('msg'=>'没有点赞过','code'=>'500'),320);exit();
			}
		// }
	}
	//地摊出价
	public function doPageMarketfee(){
		global $_W,$_GPC;
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$market_id=pdo_get('zh_gjw_marketbuy',array('market_id'=>$_GPC['market_id'],'u_id'=>$user['id'],'uniacid'=>$_W['uniacid']));
		$market=pdo_getall('zh_gjw_marketbuy',array('market_id'=>$_GPC['market_id'],'uniacid'=>$_W['uniacid']), array() , '' , 'fee DESC' , array());
      			function ressort($market){
                  for($i=1;$i<count($market);$i++)
                   { //该层循环用来控制每轮 冒出一个数 需要比较的次数
                      for($k=0;$k<count($market)-$i;$k++)
                      {
                         if($market[$k]['fee']<$market[$k+1]['fee'])
                          {
                              $tmp=$market[$k+1];
                              $market[$k+1]=$market[$k];
                              $market[$k]=$tmp;
                          }
                      }
                  }
              	return $market;
              	}
			$market=ressort($market);
		if (empty($market)) {
			// if (empty($shot_id)) {
				$data['market_id']=$_GPC['market_id'];
				$data['u_id']=$user['id'];
				$data['fee']=$_GPC['money'];
				$data['uniacid']=$_W['uniacid'];
				$data['time']=date('Y-m-d H:i:s',time());
				$res=pdo_insert('zh_gjw_marketbuy',$data);
				if ($res) {
		    		echo json_encode(array('msg'=>'记录成功','code'=>'200'),320);exit();
				}else{
					echo json_encode(array('msg'=>'记录失败','code'=>'500'),320);exit();
				}
			// }else{
				
			// }
		}else{
			if (empty($market_id)) {
				$data['market_id']=$_GPC['market_id'];
				$data['u_id']=$user['id'];
				$data['fee']=$_GPC['money'];
				$data['uniacid']=$_W['uniacid'];
				$data['time']=date('Y-m-d H:i:s',time());
				$res=pdo_insert('zh_gjw_marketbuy',$data);
				if ($res) {
		    		echo json_encode(array('msg'=>'记录成功','code'=>'200'),320);exit();
				}else{
					echo json_encode(array('msg'=>'记录失败','code'=>'500'),320);exit();
				}
			}else{
				$data['fee']=$_GPC['money'];
				$data['time']=date('Y-m-d H:i:s',time());
				$res=pdo_update('zh_gjw_marketbuy',$data,array('market_id'=>$_GPC['market_id'],'u_id'=>$user['id'],'uniacid'=>$_W['uniacid']));
				if ($res) {
		    		echo json_encode(array('msg'=>'更新成功','code'=>'200'),320);exit();
				}else{
					echo json_encode(array('msg'=>'更新失败','code'=>'500'),320);exit();
				}
			}
		}
			
		

	}
	//地摊详情查询出价者
	public function doPageMarketuser(){
		global $_W,$_GPC;
		$res=pdo_fetchall("SELECT a.*,b.avatar,b.username FROM " . tablename('zh_gjw_marketbuy'). " a"  . " left join " . tablename("zh_gjw_register") . " b on a.u_id=b.id WHERE  a.market_id=:market_id and a.uniacid=:uniacid", array(':market_id'=>$_GPC['market_id'],':uniacid'=>$_W['uniacid']));
		
		function ressort($res){
			for($i=1;$i<count($res);$i++)
			 { //该层循环用来控制每轮 冒出一个数 需要比较的次数
			    for($k=0;$k<count($res)-$i;$k++)
			    {
			       if($res[$k]['fee']<$res[$k+1]['fee'])
			        {
			            $tmp=$res[$k+1];
			            $res[$k+1]=$res[$k];
			            $res[$k]=$tmp;
			        }
			    }
			}
  		return $res;
		}
		$res=ressort($res);
		if (empty($res)) {
			echo json_encode(array('msg'=>'没有相应出价者','code'=>'500'),320);exit();
		}else{
			echo json_encode(array('msg'=>'找到啦','code'=>'200','res'=>$res),320);exit();
		}
	}

	//我的地摊竞拍ing
	public function doPageMymarketing(){
		global $_W,$_GPC;
		$arr=array();
		$openid=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$res=pdo_fetchall("SELECT a.*,b.img,b.totime,b.title,b.view,b.agree,b.video,b.phone,b.lmoney,b.time as markettime FROM " . tablename('zh_gjw_marketbuy'). " a"  . " left join " . tablename("zh_gjw_marketpublish") . " b on a.market_id=b.id WHERE  a.u_id=:u_id and a.uniacid=:uniacid", array(':u_id'=>$openid['id'],':uniacid'=>$_W['uniacid']));
			function ressort($allshot){
				for($j=1;$j<count($allshot);$j++)
				 { //该层循环用来控制每轮 冒出一个数 需要比较的次数
				    for($k=0;$k<count($allshot)-$j;$k++)
				    {
				       if($allshot[$k]['fee']<$allshot[$k+1]['fee'])
				        {
				            $tmp=$allshot[$k+1];
				            $allshot[$k+1]=$allshot[$k];
				            $allshot[$k]=$tmp;
				        }
				    }
				}
	  		return $allshot;
			}
		for ($i=0; $i <count($res) ; $i++) { 

			if (in_array(0,explode(",",$res[$i]['view']))) {
				$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
			}else{
				$res[$i]['view']=count(explode(",",$res[$i]['view']));
			}
			if (in_array(0,explode(",",$res[$i]['agree']))) {
				$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
			}else{
				$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
			}
			
			$cusname=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone'],'uniacid'=>$_W['uniacid']));
			if ($cusname) {
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $cusname['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['reputation']=$cusname['reputation'];
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['cusname']=$cusname['cusname'];
				$res[$i]['level_name']=$cusname['level_name'];
				$res[$i]['storeimg']=$cusname['storeimg'];
			}else{
				$res[$i]['cusname']='';
				$res[$i]['storeimg']='';
				$res[$i]['level_name']='';
			}

			$allshot=pdo_getall('zh_gjw_marketbuy',array('market_id'=>$res[$i]['market_id']));
			
			$allshot=ressort($allshot);
			$res[$i]['max']=$allshot[0]['fee'];
			$res[$i]['totimesjc']=strtotime($res[$i]['markettime'])+86400*5;
			$res[$i]['totime']=date('Y-m-d H:i:s',$res[$i]['totimesjc']);
          
			if ($res[$i]['tole']==1) {
				array_splice($res,$i,1);
			}
			if ($res[$i]['totimesjc']>time()) {
				array_push($arr,$res[$i]);
			}
          
		}

		if (empty($arr)) {
			echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
		}else{
			echo json_encode(array('msg'=>'找到啦','code'=>'200','res'=>$arr),320);exit();
		}
	}
	//我的竞拍待支付
	public function doPageMymarkettopay(){
		global $_W,$_GPC;
		$arr=array();
		$openid=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$res=pdo_fetchall("SELECT a.*,b.img,b.totime,b.title,b.view,b.agree,b.video,b.phone,b.lmoney,b.exfee,b.time as markettime FROM " . tablename('zh_gjw_marketbuy'). " a"  . " left join " . tablename("zh_gjw_marketpublish") . " b on a.market_id=b.id WHERE  a.u_id=:u_id and a.uniacid=:uniacid", array(':u_id'=>$openid['id'],':uniacid'=>$_W['uniacid']));
				
			function ressort($allshot){
				for($j=1;$j<count($allshot);$j++)
				 { //该层循环用来控制每轮 冒出一个数 需要比较的次数
				    for($k=0;$k<count($allshot)-$j;$k++)
				    {
				       if($allshot[$k]['fee']<$allshot[$k+1]['fee'])
				        {
				            $tmp=$allshot[$k+1];
				            $allshot[$k+1]=$allshot[$k];
				            $allshot[$k]=$tmp;
				        }
				    }
				}
	  		return $allshot;
			}
		for ($i=0; $i <count($res) ; $i++) { 

			if (in_array(0,explode(",",$res[$i]['view']))) {
				$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
			}else{
				$res[$i]['view']=count(explode(",",$res[$i]['view']));
			}
			if (in_array(0,explode(",",$res[$i]['agree']))) {
				$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
			}else{
				$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
			}

			$cusname=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone'],'uniacid'=>$_W['uniacid']));
			if ($cusname) {
				$res[$i]['cusname']=$cusname['cusname'];
				$res[$i]['storeimg']=$cusname['storeimg'];
			}else{
				$res[$i]['cusname']='';
				$res[$i]['storeimg']='';
			}

			$allshot=pdo_getall('zh_gjw_marketbuy',array('market_id'=>$res[$i]['market_id']));
			
			$allshot=ressort($allshot);
			$res[$i]['max']=$allshot[0]['fee'];
			$res[$i]['totimesjc']=strtotime($res[$i]['markettime'])+86400*5;
          	$ttotime=strtotime($res[$i]['markettime'])+86400*7;
			$res[$i]['totime']=date('Y-m-d H:i:s',$res[$i]['totimesjc']);
			if ($res[$i]['totimesjc']<time() && time()<$ttotime && $res[$i]['pay']!=1) {
				array_push($arr,$res[$i]);
			}
		}

		if (empty($arr)) {
			echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
		}else{
			echo json_encode(array('msg'=>'找到啦','code'=>'200','res'=>$arr),320);exit();
		}
	}
	//我的地摊竞拍结束
	public function doPageMymarketover(){
		global $_W,$_GPC;
		$arr=array();
		$openid=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$res=pdo_fetchall("SELECT a.*,b.img,b.totime,b.title,b.view,b.agree,b.video,b.phone,b.lmoney,b.exfee FROM " . tablename('zh_gjw_marketbuy'). " a"  . " left join " . tablename("zh_gjw_marketpublish") . " b on a.market_id=b.id WHERE  a.u_id=:u_id and a.uniacid=:uniacid", array(':u_id'=>$openid['id'],':uniacid'=>$_W['uniacid']));
			function ressort($allshot){
				for($j=1;$j<count($allshot);$j++)
				 { //该层循环用来控制每轮 冒出一个数 需要比较的次数
				    for($k=0;$k<count($allshot)-$j;$k++)
				    {
				       if($allshot[$k]['fee']<$allshot[$k+1]['fee'])
				        {
				            $tmp=$allshot[$k+1];
				            $allshot[$k+1]=$allshot[$k];
				            $allshot[$k]=$tmp;
				        }
				    }
				}
	  		return $allshot;
			}
		for ($i=0; $i <count($res) ; $i++) { 
			$allshot=pdo_getall('zh_gjw_marketbuy',array('market_id'=>$res[$i]['market_id']));
			
			$allshot=ressort($allshot);
			$res[$i]['max']=$allshot[0]['fee'];
			$res[$i]['totimesjc']=strtotime($res[$i]['totime']);
			if (strtotime($res[$i]['totime'])<time() && $res[$i]['pay']==1) {
				array_push($arr,$res[$i]);
			}
		}

		if (empty($arr)) {
			echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
		}else{
			echo json_encode(array('msg'=>'找到啦','code'=>'200','res'=>$arr),320);exit();
		}
	}
	//生成地摊订单
	public function doPageMarketorder(){
		global $_W,$_GPC;
		$cus_id=pdo_get('zh_gjw_marketpublish',array('id'=>$_GPC['p_id']));
		$cusm=pdo_get('zh_gjw_cusmanage',array('phone'=>$cus_id['phone']));
		$u_id=pdo_get('zh_gjw_register',array('uniacid'=>$_W['uniacid'],'openid'=>$_GPC['openid']));
		$data['u_id']=$u_id['id'];
		$data['formid']=$_GPC['formid'];
		$data['cus_id']=$cusm['id'];
		$data['p_id']=$_GPC['p_id'];
		$data['type']=$_GPC['type'];
		$data['ordernum']=date('Ymdhis').$u_id['id'].rand(10,99);
		$data['ofee']=$_GPC['ofee'];
		$data['message']=$_GPC['message'];
		$data['phone']=$_GPC['phone'];
		$data['uname']=$_GPC['name'];
		$data['state']=1;
		$data['address']=$_GPC['address'];
		$data['num']=$_GPC['num'];
		$data['ofees']=$_GPC['ofees'];
		$data['uniacid']=$_W['uniacid'];
		$data['time']=date('Y-m-d H:i:s',time());
		$data['timesjc']=time();
		$res=pdo_insert('zh_gjw_orders',$data);
		$res_id=pdo_insertid();
		if (empty($res)) {
			echo json_encode(array('msg'=>'提交失败','code'=>'500'),320);exit();
		}
		echo json_encode(array('msg'=>'提交成功','code'=>'200','res_id'=>$res_id),320);exit();

	}
	//地摊订单支付
	public function doPageMarketorderpay(){
		global $_W,$_GPC;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		pdo_update('zh_gjw_orders', array('paycode' =>$out_trade_no), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		$root=$_W['siteroot']; 
		$total_fee =$_GPC['ofees'];
		if($total_fee>0)
		{
			$body = "地摊订单支付";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
		echo json_encode($return);
	}

	//地摊订单支付成功改变state
	public function doPageMarketorderpaysuccess(){
		global $_W, $_GPC;
		/*function getaccess_token($_W){
          $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
          $appid=$res['appid'];
          $secret=$res['appsecret'];
          $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL,$url);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
          $data = curl_exec($ch);
          curl_close($ch);
          $data = json_decode($data,true);
          return $data['access_token'];
        }*/
        function set_msg($_W,$res){
            //$access_token = getaccess_token($_W);
            $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
            $user=pdo_get('zh_gjw_register',array('id'=>$res['u_id']));
            $orders=pdo_get('zh_gjw_orders',array('id'=>$res['id']));
            $marketname=pdo_get('zh_gjw_marketpublish',array('id'=>$res['p_id']));
            $formwork ='{
                "touser": "'.$user["openid"].'",
                "template_id": "'.$ress["templeidos"].'",
                "form_id":"'.$orders['formid'].'",
                "data": {
                    "keyword1": {
                        "value": "'.$orders['time'].'",
                        "color": "#173177"
                    },
                    "keyword2": {
                        "value":"'.$orders['paytime'].'",
                        "color": "#173177"
                    },
                    "keyword3": {
                        "value":"'.$marketname['title'].'",
                        "color": "#173177"
                    },
                    "keyword4": {
                        "value":"'.$orders['ordernum'].'",
                        "color": "#173177"
                    },
                    "keyword5": {
                        "value":"'.$orders['ofees'].'",
                        "color": "#173177"
                    },
                    "keyword6": {
                        "value":"'.$orders['id'].'",
                        "color": "#173177"
                    },
                    "keyword7": {
                        "value":"地摊购买成功",
                        "color": "#173177"
                    }
                }  
            }';
            $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL,$url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
            curl_setopt($ch, CURLOPT_POST,1);
            curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
            $data = curl_exec($ch);
            curl_close($ch);
           return $data;
        }
		$res = pdo_update('zh_gjw_orders', array('state' =>2,'paytime' =>date('Y-m-d H:i:s')), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		$ress = pdo_update('zh_gjw_marketbuy', array('pay' =>1), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if ($res) {
			set_msg($_W,$res);
                file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=GetGrade&m=zh_gjw&order_id=" . $_GPC['res_id']);//修改等级
			echo json_encode(array('msg'=>'成功','code'=>'200'),320);exit();
		}
		echo json_encode(array('msg'=>'失败','code'=>'500'),320);exit();
	}
	//获取用户信息
	public function doPageUserinfo(){
		global $_W, $_GPC;
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		if ($user){
				echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$user),320);exit();
		}else{
			echo json_encode(array('msg'=>'出错了','code'=>'500'),320);exit();
		}

	}
	//我的店铺(自己)
	public function doPageMyselfstore(){
		global $_W, $_GPC;
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		if ($_GPC['type']=0) {
			$db=pdo_getall('zh_gjw_dbpublish',array('phone'=>$user['phone'],'uniacid'=>$_W['uniacid']));
			if ($db) {
				echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$db),320);exit();
			}
			echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
		}
		if ($_GPC['type']=1) {
			$shot=pdo_getall('zh_gjw_shotpublish',array('phone'=>$user['phone'],'uniacid'=>$_W['uniacid']));
			if ($shot) {
				echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$shot),320);exit();
			}
			echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
		}
		if ($_GPC['type']=2) {
			$market=pdo_getall('zh_gjw_marketpublish',array('phone'=>$user['phone'],'uniacid'=>$_W['uniacid']));
			if ($market) {
				echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$market),320);exit();
			}
			echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
		}
		if ($_GPC['type']=3) {
			$pri=pdo_getall('zh_gjw_pripublish',array('phone'=>$user['phone'],'uniacid'=>$_W['uniacid']));
			if ($pri) {
				echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$pri),320);exit();
			}
			echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
		}
	}
	//商家店铺
	public function doPageCusstore(){
		global $_W, $_GPC;
		// if ($_GPC['type']=0) {
		// 	$dbid=pdo_get('zh_gjw_dbpublish',array('id'=>$_GPC['pid'],'uniacid'=>$_W['uniacid']));
		// 	$db=pdo_getall('zh_gjw_dbpublish',array('phone'=>$dbid['phone'],'uniacid'=>$_W['uniacid']));
		// 	if ($db) {
		// 		echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$db),320);exit();
		// 	}
		// 	echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
		// }
		// if ($_GPC['type']=1) {
		// 	$shotid=pdo_get('zh_gjw_shotpublish',array('id'=>$_GPC['pid'],'uniacid'=>$_W['uniacid']));
		// 	$shot=pdo_getall('zh_gjw_shotpublish',array('phone'=>$shotid['phone'],'uniacid'=>$_W['uniacid']));
		// 	if ($shot) {
		// 		echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$shot),320);exit();
		// 	}
		// 	echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
		// }
		// if ($_GPC['type']=2) {
		// 	$marketid=pdo_get('zh_gjw_marketpublish',array('id'=>$_GPC['pid'],'uniacid'=>$_W['uniacid']));
		// 	$market=pdo_getall('zh_gjw_marketpublish',array('phone'=>$marketid['phone'],'uniacid'=>$_W['uniacid']));
		// 	if ($market) {
		// 		echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$market),320);exit();
		// 	}
		// 	echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
		// }
		// if ($_GPC['type']=3) {
		// 	$priid=pdo_get('zh_gjw_pripublish',array('id'=>$_GPC['pid'],'uniacid'=>$_W['uniacid']));
		// 	$pri=pdo_getall('zh_gjw_pripublish',array('phone'=>$priid['phone'],'uniacid'=>$_W['uniacid']));
		// 	if ($pri) {
		// 		echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$pri),320);exit();
		// 	}
		// 	echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
		// }
	}
	//判断是否收藏
	public function doPageIslovestore(){
		global $_W, $_GPC;
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$store=pdo_get('zh_gjw_cusmanage',array('phone'=>$_GPC['phone'],'uniacid'=>$_W['uniacid']));
		$id=pdo_get('zh_gjw_love',array('u_id'=>$user['id'],'store_id'=>$store['id'],'uniacid'=>$_W['uniacid']));
		if ($id) {
			echo json_encode(array('msg'=>'收藏过了','code'=>'200'),320);exit();
		}
		echo json_encode(array('msg'=>'没有收藏','code'=>'500'),320);exit();
	}
	//收藏店铺
	public function doPageLovestore(){
		global $_W, $_GPC;
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$store=pdo_get('zh_gjw_cusmanage',array('phone'=>$_GPC['phone'],'uniacid'=>$_W['uniacid']));
		$id=pdo_get('zh_gjw_love',array('u_id'=>$user['id'],'store_id'=>$store['id'],'uniacid'=>$_W['uniacid']));

		if ($id) {
			echo json_encode(array('msg'=>'收藏过了','code'=>'201'),320);exit();
		}else{
			$data['u_id']=$user['id'];
			$data['store_id']=$store['id'];
			$data['uniacid']=$_W['uniacid'];
			$data['time']=date('Y-m-d H:i:s',time());
			$res=pdo_insert('zh_gjw_love',$data);
			if ($res) {
				echo json_encode(array('msg'=>'收藏成功','code'=>'200'),320);exit();
			}
			echo json_encode(array('msg'=>'收藏失败','code'=>'500'),320);exit();
		}
	}
	//我的收藏列表
	public function doPageMylovestore(){
		global $_W, $_GPC;
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$stores=pdo_getall('zh_gjw_love',array('u_id'=>$user['id'],'uniacid'=>$_W['uniacid']));
		$res=pdo_fetchall("SELECT a.*,b.avatar,b.cusname,b.storeimg,b.shotcate,b.phone,b.level_name,b.reputation,b.openid FROM " . tablename('zh_gjw_love'). " a"  . " left join " . tablename("zh_gjw_cusmanage") . " b on a.store_id=b.id WHERE  a.uniacid=:uniacid and a.u_id=:u_id", array(':uniacid'=>$_W['uniacid'],':u_id'=>$user['id']));
		if ($res) {
			for ($i=0; $i <count($res) ; $i++) { 
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $res[$i]['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['xybzj']=$totalmoney['total_money'];
			}
			echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
	}
	//店铺信息
	public function doPageLovestoreinfo(){
		global $_W, $_GPC;
		$allorderassess=array();
		// $db=pdo_getall('zh_gjw_dbpublish',array('phone'=>$_GPC['phone'],'uniacid'=>$_W['uniacid']));
		$reso=pdo_fetchall("SELECT a.* FROM ".tablename('zh_gjw_orders'). " a left join " . tablename("zh_gjw_dbpublish") . " b on a.p_id=b.id WHERE a.uniacid=:uniacid and b.phone=:phone and a.type=:type ORDER BY a.time desc", array(':uniacid'=>$_W['uniacid'],':type'=>1,':phone'=>$_GPC['phone']));
		$rest=pdo_fetchall("SELECT a.* FROM ".tablename('zh_gjw_orders'). " a left join " . tablename("zh_gjw_shotpublish") . " b on a.p_id=b.id WHERE a.uniacid=:uniacid and b.phone=:phone and a.type=:type ORDER BY a.time desc", array(':uniacid'=>$_W['uniacid'],':type'=>2,':phone'=>$_GPC['phone']));
		$resth=pdo_fetchall("SELECT a.* FROM ".tablename('zh_gjw_orders'). " a left join " . tablename("zh_gjw_marketpublish") . " b on a.p_id=b.id WHERE a.uniacid=:uniacid and b.phone=:phone and a.type=:type ORDER BY a.time desc", array(':uniacid'=>$_W['uniacid'],':type'=>3,':phone'=>$_GPC['phone']));
		$resf=pdo_fetchall("SELECT a.* FROM ".tablename('zh_gjw_orders'). " a left join " . tablename("zh_gjw_storepublish") . " b on a.p_id=b.id WHERE a.uniacid=:uniacid and b.phone=:phone and a.type=:type ORDER BY a.time desc", array(':uniacid'=>$_W['uniacid'],':type'=>4,':phone'=>$_GPC['phone']));
		$resfi=pdo_fetchall("SELECT a.* FROM ".tablename('zh_gjw_orders'). " a left join " . tablename("zh_gjw_pripublish") . " b on a.p_id=b.id WHERE a.uniacid=:uniacid and b.phone=:phone and a.type=:type ORDER BY a.time desc", array(':uniacid'=>$_W['uniacid'],':type'=>5,':phone'=>$_GPC['phone']));
		$allorder=$resf+$reso+$rest+$resth+$resfi;
		if (count($allorder)>0) {
			for ($i=0; $i <count($allorder) ; $i++) { 
				$allorderassesss=pdo_getall('zh_gjw_orderassess',array('p_id'=>$allorder[$i]['id'],'uniacid'=>$_W['uniacid']));
				for ($j=0; $j <count($allorderassesss) ; $j++) { 
					array_push($allorderassess,$allorderassesss[$j]);
				}
			}
		}
		$pricetag=0;
		$speedtag=0;
		$packtag=0;
		$babytag=0;
		$confidetag=0;
		$desstar=0;
		$speedstar=0;
		if (count($allorderassess)>0) {
			for ($k=0; $k <count($allorderassess) ; $k++) { 
				if ($allorderassess[$k]['pricetag']>0) {
					$pricetag+=$allorderassess[$k]['pricetag'];
				}
				if ($allorderassess[$k]['speedtag']>0) {
					$speedtag+=$allorderassess[$k]['speedtag'];
				}
				if ($allorderassess[$k]['packtag']>0) {
					$packtag+=$allorderassess[$k]['packtag'];
				}
				if ($allorderassess[$k]['babytag']>0) {
					$babytag+=$allorderassess[$k]['babytag'];
				}
				if ($allorderassess[$k]['confidetag']>0) {
					$confidetag+=$allorderassess[$k]['confidetag'];
				}
				if ($allorderassess[$k]['desstar']>0) {
					$desstar+=$allorderassess[$k]['desstar'];
				}
				if ($allorderassess[$k]['speedstar']>0) {
					$speedstar+=$allorderassess[$k]['speedstar'];
				}

			}
			$stars=$speedstar+$desstar;
			$counts=2*count($allorderassess);
			$star=ceil($stars/$counts);
		}else{
			$star=0;
		}
				
		echo json_encode(array('msg'=>'查询成功','code'=>'200','star'=>$star,'pricetag'=>$pricetag,'speedtag'=>$speedtag,'packtag'=>$packtag,'babytag'=>$babytag,'confidetag'=>$confidetag),320);exit();
	}
	//店铺详情db
	public function doPageLoveenterstoredb(){
		global $_W, $_GPC;

		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=6;
		$where=' WHERE  uniacid=:uniacid and phone=:phone ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':phone']=$_GPC['phone'];
	    $sql="SELECT * FROM ".tablename('zh_gjw_dbpublish') .$where." ORDER BY time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_dbpublish').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);

		if ($res) {
			for ($i=0; $i <count($res) ; $i++) { 

				 $resu=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone']));
                  $totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
                  $res[$i]['xybzj']=$totalmoney['total_money'];
                  $res[$i]['reputation']=$resu['reputation'];
                  $res[$i]['level_name']=$resu['level_name'];
				 $res[$i]['cusname']=$resu['cusname'];
				 $res[$i]['storeimg']=$resu['storeimg'];

				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
			}
			echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
		// $db=pdo_getall('zh_gjw_dbpublish',array('phone'=>$_GPC['phone'],'uniacid'=>$_W['uniacid']));
		// $shot=pdo_getall('zh_gjw_shotpublish',array('phone'=>$_GPC['phone'],'uniacid'=>$_W['uniacid']));
		// $market=pdo_getall('zh_gjw_marketpublish',array('phone'=>$_GPC['phone'],'uniacid'=>$_W['uniacid']));
		// $pri=pdo_getall('zh_gjw_pripublish',array('phone'=>$_GPC['phone'],'uniacid'=>$_W['uniacid']));
		// $all=$db+$shot+$market;
		// echo json_encode(array('msg'=>'查询成功','code'=>'200','db'=>$db,'shot'=>$shot,'market'=>$market,'pri'=>$pri,'all'=>$all),320);exit();
	}

	//店铺详情微拍
	public function doPageLoveenterstoreshot(){
		global $_W, $_GPC;

		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=6;
		$where=' WHERE  uniacid=:uniacid and phone=:phone ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':phone']=$_GPC['phone'];
	    $sql="SELECT * FROM ".tablename('zh_gjw_shotpublish') .$where." ORDER BY time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_shotpublish').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);

		if ($res) {
			for ($i=0; $i <count($res) ; $i++) { 

				 $resu=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['reputation']=$resu['reputation'];
				$res[$i]['level_name']=$resu['level_name'];
				 $res[$i]['cusname']=$resu['cusname'];
				 $res[$i]['storeimg']=$resu['storeimg'];

				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
			}
			echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
	}
	//店铺详情地摊
	public function doPageLoveenterstoremarket(){
		global $_W, $_GPC;

		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=6;
		$where=' WHERE  uniacid=:uniacid and phone=:phone ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':phone']=$_GPC['phone'];
	    $sql="SELECT * FROM ".tablename('zh_gjw_marketpublish') .$where." ORDER BY time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_marketpublish').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);

		if ($res) {
			for ($i=0; $i <count($res) ; $i++) { 

				 $resu=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['reputation']=$resu['reputation'];
				$res[$i]['level_name']=$resu['level_name'];
				 $res[$i]['cusname']=$resu['cusname'];
				 $res[$i]['storeimg']=$resu['storeimg'];

				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
			}
			echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
	}
	
	//店铺详情商城
	public function doPageLoveenterstorestore(){
		global $_W, $_GPC;

		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=6;
		$where=' WHERE  uniacid=:uniacid and phone=:phone ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':phone']=$_GPC['phone'];
	    $sql="SELECT * FROM ".tablename('zh_gjw_storepublish') .$where." ORDER BY time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_storepublish').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);

		if ($res) {
			for ($i=0; $i <count($res) ; $i++) { 


				 $resu=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['reputation']=$resu['reputation'];
				$res[$i]['level_name']=$resu['level_name'];
				 $res[$i]['cusname']=$resu['cusname'];
				 $res[$i]['storeimg']=$resu['storeimg'];

				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
			}
			echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
	}
	//店铺详情全部
	public function doPageLoveenterstoreall(){
		global $_W, $_GPC;

		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=6;
		$where=' WHERE  uniacid=:uniacid and phone=:phone ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':phone']=$_GPC['phone'];
	    $sql="SELECT * FROM ".tablename('zh_gjw_marketpublish') .$where." ORDER BY time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_marketpublish').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		if ($res) {
			for ($i=0; $i <count($res) ; $i++) { 
				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
			}
			echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
	}
	//删除收藏店铺
    public function doPageStorelovedelete(){
    	global $_GPC,$_W;
    	$res=pdo_delete('zh_gjw_love',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if ($res) {
		echo json_encode(array('msg'=>'成功','code'=>'200'),320);exit();
		}
		echo json_encode(array('msg'=>'失败','code'=>'500'),320);exit();

    }
	//商家抖宝管理
	public function doPageDbm(){
		global $_W, $_GPC;
		// $res=pdo_getall('zh_gjw_dbpublish',array('phone'=>$_GPC['phone'],'uniacid'=>$_W['uniacid']));
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=10;
		$where=' WHERE  uniacid=:uniacid and phone=:phone ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':phone']=$_GPC['phone'];
	    $sql="SELECT * FROM ".tablename('zh_gjw_dbpublish') .$where." ORDER BY time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_dbpublish').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		if ($res) {
			echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
	}
	//商家微拍管理
	public function doPageShotm(){
		global $_W, $_GPC;
		// $res=pdo_getall('zh_gjw_shotpublish',array('phone'=>$_GPC['phone'],'uniacid'=>$_W['uniacid']));
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=10;
		$where=' WHERE  uniacid=:uniacid and phone=:phone ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':phone']=$_GPC['phone'];
	    $sql="SELECT * FROM ".tablename('zh_gjw_shotpublish') .$where." ORDER BY time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_shotpublish').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		if ($res) {
			for ($i=0; $i <count($res) ; $i++) { 

				$res[$i]['imgs']=explode(',', $res[$i]['img']);
				$res[$i]['videoimg']=$res[$i]['imgs'][0];
			}
			echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
	}
	//商家地摊管理
	public function doPageMarketm(){
		global $_W, $_GPC;
		// $res=pdo_getall('zh_gjw_marketpublish',array('phone'=>$_GPC['phone'],'uniacid'=>$_W['uniacid']));
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=10;
		$where=' WHERE  uniacid=:uniacid and phone=:phone ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':phone']=$_GPC['phone'];
	    $sql="SELECT * FROM ".tablename('zh_gjw_marketpublish') .$where." ORDER BY time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_marketpublish').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		if ($res) {
			for ($i=0; $i <count($res) ; $i++) { 

				$res[$i]['imgs']=explode(',', $res[$i]['img']);
				$res[$i]['videoimg']=$res[$i]['imgs'][0];
			}
			echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
	}
  	//商家商店管理
	public function doPageStorem(){
		global $_W, $_GPC;
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=10;
		$where=' WHERE  uniacid=:uniacid and phone=:phone ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':phone']=$_GPC['phone'];
	    $sql="SELECT * FROM ".tablename('zh_gjw_storepublish') .$where." ORDER BY time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_storepublish').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		if ($res) {
			for ($i=0; $i <count($res) ; $i++) { 

				$res[$i]['imgs']=explode(',', $res[$i]['img']);
				$res[$i]['videoimg']=$res[$i]['imgs'][0];
			}
			echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
	}
	//商家定制管理
	public function doPagePrim(){
		global $_W, $_GPC;
		// $res=pdo_getall('zh_gjw_pripublish',array('phone'=>$_GPC['phone'],'uniacid'=>$_W['uniacid']));
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=10;
		$where=' WHERE  uniacid=:uniacid and phone=:phone ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':phone']=$_GPC['phone'];
	    $sql="SELECT * FROM ".tablename('zh_gjw_pripublish') .$where." ORDER BY time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_pripublish').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		if ($res) {
			for ($i=0; $i <count($res) ; $i++) { 

				$res[$i]['imgs']=explode(',', $res[$i]['img']);
				$res[$i]['videoimg']=$res[$i]['imgs'][0];
			}
			echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
	}
	//商家后台删除数据
	public function doPageMdetele(){
		global $_W, $_GPC;
		if ($_GPC['mtype']==0) {
			$res=pdo_delete('zh_gjw_dbpublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
			if ($res) {
			echo json_encode(array('msg'=>'删除成功','code'=>'200'),320);exit();
			}
			echo json_encode(array('msg'=>'删除失败','code'=>'500'),320);exit();
		}
		if ($_GPC['mtype']==1) {
			$res=pdo_delete('zh_gjw_shotpublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
			if ($res) {
			echo json_encode(array('msg'=>'删除成功','code'=>'200'),320);exit();
			}
			echo json_encode(array('msg'=>'删除失败','code'=>'500'),320);exit();
		}
		if ($_GPC['mtype']==2) {
			$res=pdo_delete('zh_gjw_marketpublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
			if ($res) {
			echo json_encode(array('msg'=>'删除成功','code'=>'200'),320);exit();
			}
			echo json_encode(array('msg'=>'删除失败','code'=>'500'),320);exit();
		}
		if ($_GPC['mtype']==3) {
			$res=pdo_delete('zh_gjw_pripublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
			if ($res) {
			echo json_encode(array('msg'=>'删除成功','code'=>'200'),320);exit();
			}
			echo json_encode(array('msg'=>'删除失败','code'=>'500'),320);exit();
		}
	}
	//地摊分类联合
	public function doPageCatestopdw(){
		global $_GPC, $_W;
		$res=pdo_getall('zh_gjw_marketcate',array('showhide'=>1,'uniacid'=>$_W['uniacid'],'p_id'=>0), array() , '' , 'sort ASC' , array());
		for ($i=0; $i <count($res) ; $i++) { 
			$res[$i]['arr']=array();
			$res[$i]['arr']=pdo_getall('zh_gjw_marketcate',array('showhide'=>1,'uniacid'=>$_W['uniacid'],'p_id'=>$res[$i]['id']), array() , '' , 'id ASC' , array());

		}
		echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res),320);exit();
	}
	//个人订单/全部
	public function doPagePersonordersall(){
		global $_W, $_GPC;
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
	    $where=' WHERE  a.uniacid=:uniacid and b.openid=:openid and a.udelete=:udelete ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':openid']=$_GPC['openid'];
	    $data[':udelete']=0;
    	$sql="SELECT a.*,b.openid FROM ".tablename('zh_gjw_orders'). " a left join " . tablename("zh_gjw_register") . " b on a.u_id=b.id" .$where." ORDER BY a.time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_orders'). " a left join " . tablename("zh_gjw_register") . " b on a.u_id=b.id" .$where." ORDER BY a.time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		for($i=0; $i <count($res) ; $i++){
			if ($res[$i]['type']==1) {
				$dbimg[$i]=pdo_get('zh_gjw_dbpublish',array('id'=>$res[$i]['p_id']));
				$resu[$i]=pdo_get('zh_gjw_cusmanage',array('phone'=>$dbimg[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu[$i]['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['reputation']=$resu[$i]['reputation'];
				$res[$i]['cusname']=$resu[$i]['cusname'];
				$res[$i]['storeimg']=$resu[$i]['storeimg'];
				$res[$i]['level_name']=$resu[$i]['level_name'];
				if($dbimg[$i]){
					$res[$i]['img']=$dbimg[$i]['videoimg'];
					$res[$i]['title']=$dbimg[$i]['dbname'];
					$res[$i]['exfee']=$dbimg[$i]['exfee'];
				}else{
					array_splice($res,$i,1);
				}
			}
			if ($res[$i]['type']==2) {
				$shotimg[$i]=pdo_get('zh_gjw_shotpublish',array('id'=>$res[$i]['p_id']));
				$resu[$i]=pdo_get('zh_gjw_cusmanage',array('phone'=>$shotimg[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu[$i]['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['reputation']=$resu[$i]['reputation'];
				$res[$i]['cusname']=$resu[$i]['cusname'];
				$res[$i]['storeimg']=$resu[$i]['storeimg'];
				$res[$i]['level_name']=$resu[$i]['level_name'];
				if($shotimg[$i]){
					$res[$i]['img']=$shotimg[$i]['img'];
					$res[$i]['title']=$shotimg[$i]['title'];
					$res[$i]['exfee']=$shotimg[$i]['exfee'];
				}else{
					array_splice($res,$i,1);
				}
			}
			if ($res[$i]['type']==3) {
				$marketimg[$i]=pdo_get('zh_gjw_marketpublish',array('id'=>$res[$i]['p_id']));
				$resu[$i]=pdo_get('zh_gjw_cusmanage',array('phone'=>$marketimg[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu[$i]['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['reputation']=$resu[$i]['reputation'];
				$res[$i]['cusname']=$resu[$i]['cusname'];
				$res[$i]['storeimg']=$resu[$i]['storeimg'];
				$res[$i]['level_name']=$resu[$i]['level_name'];
				if($marketimg[$i]){
					$res[$i]['img']=$marketimg[$i]['img'];
					$res[$i]['title']=$marketimg[$i]['title'];
					$res[$i]['exfee']=$marketimg[$i]['exfee'];
				}else{
					array_splice($res,$i,1);
				}
			}
			if ($res[$i]['type']==4) {
				$priimg[$i]=pdo_get('zh_gjw_storepublish',array('id'=>$res[$i]['p_id']));
				$resu[$i]=pdo_get('zh_gjw_cusmanage',array('phone'=>$priimg[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu[$i]['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['reputation']=$resu[$i]['reputation'];
				$res[$i]['cusname']=$resu[$i]['cusname'];
				$res[$i]['storeimg']=$resu[$i]['storeimg'];
				$res[$i]['level_name']=$resu[$i]['level_name'];
				if($priimg[$i]){
					$res[$i]['img']=$priimg[$i]['img'];
					$res[$i]['title']=$priimg[$i]['title'];
				}else{
					array_splice($res,$i,1);
				}
			}
			$openid_id=pdo_get('zh_gjw_register',array('uniacid'=>$_W['uniacid'],'openid'=>$_GPC['openid']));
			$is=pdo_get('zh_gjw_orderassess',array('uniacid'=>$_W['uniacid'],'u_id'=>$openid_id['id'],'p_id'=>$res[$i]['id']));
			if ($is) {
				$res[$i]['isass']=1;
			}else{
				$res[$i]['isass']=0;
			}
		}
		if ($res) {
			echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
	}
	//个人订单
	public function doPagePersonorders(){
		global $_W, $_GPC;
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
	    $where=' WHERE  a.uniacid=:uniacid and a.state=:state and b.openid=:openid and a.udelete=:udelete ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':state']=$_GPC['state'];
	    $data[':openid']=$_GPC['openid'];
	    $data[':udelete']=0;
    	$sql="SELECT a.*,b.openid FROM ".tablename('zh_gjw_orders'). " a left join " . tablename("zh_gjw_register") . " b on a.u_id=b.id" .$where." ORDER BY a.time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_orders'). " a left join " . tablename("zh_gjw_register") . " b on a.u_id=b.id" .$where." ORDER BY a.time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		for($i=0; $i <count($res) ; $i++){
			if ($res[$i]['type']==1) {
				$dbimg[$i]=pdo_get('zh_gjw_dbpublish',array('id'=>$res[$i]['p_id']));
				$resu[$i]=pdo_get('zh_gjw_cusmanage',array('phone'=>$dbimg[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu[$i]['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['reputation']=$resu[$i]['reputation'];
				$res[$i]['cusname']=$resu[$i]['cusname'];
				$res[$i]['storeimg']=$resu[$i]['storeimg'];
				$res[$i]['level_name']=$resu[$i]['level_name'];

				$res[$i]['img']=$dbimg[$i]['videoimg'];
				$res[$i]['title']=$dbimg[$i]['dbname'];
				$res[$i]['exfee']=$dbimg[$i]['exfee'];
			}
			if ($res[$i]['type']==2) {
				$shotimg[$i]=pdo_get('zh_gjw_shotpublish',array('id'=>$res[$i]['p_id']));

				$resu[$i]=pdo_get('zh_gjw_cusmanage',array('phone'=>$shotimg[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu[$i]['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['reputation']=$resu[$i]['reputation'];
				$res[$i]['cusname']=$resu[$i]['cusname'];
				$res[$i]['storeimg']=$resu[$i]['storeimg'];
				$res[$i]['level_name']=$resu[$i]['level_name'];

				$res[$i]['img']=$shotimg[$i]['img'];
				$res[$i]['title']=$shotimg[$i]['title'];
				$res[$i]['exfee']=$shotimg[$i]['exfee'];
			}
			if ($res[$i]['type']==3) {
				$marketimg[$i]=pdo_get('zh_gjw_marketpublish',array('id'=>$res[$i]['p_id']));

				$resu[$i]=pdo_get('zh_gjw_cusmanage',array('phone'=>$marketimg[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu[$i]['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['reputation']=$resu[$i]['reputation'];
				$res[$i]['cusname']=$resu[$i]['cusname'];
				$res[$i]['storeimg']=$resu[$i]['storeimg'];
				$res[$i]['level_name']=$resu[$i]['level_name'];

				$res[$i]['img']=$marketimg[$i]['img'];
				$res[$i]['title']=$marketimg[$i]['title'];
				$res[$i]['exfee']=$marketimg[$i]['exfee'];
			}
			if ($res[$i]['type']==4) {
				$priimg[$i]=pdo_get('zh_gjw_storepublish',array('id'=>$res[$i]['p_id']));
				
				$resu[$i]=pdo_get('zh_gjw_cusmanage',array('phone'=>$priimg[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu[$i]['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['reputation']=$resu[$i]['reputation'];
				$res[$i]['cusname']=$resu[$i]['cusname'];
				$res[$i]['storeimg']=$resu[$i]['storeimg'];
				$res[$i]['level_name']=$resu[$i]['level_name'];
				
				$res[$i]['img']=$priimg[$i]['img'];
				$res[$i]['title']=$priimg[$i]['title'];
			}
			$openid_id=pdo_get('zh_gjw_register',array('uniacid'=>$_W['uniacid'],'openid'=>$_GPC['openid']));
			$is=pdo_get('zh_gjw_orderassess',array('uniacid'=>$_W['uniacid'],'u_id'=>$openid_id['id'],'p_id'=>$res[$i]['id']));
			if ($is) {
				$res[$i]['isass']=1;
			}else{
				$res[$i]['isass']=0;
			}
		}
		if ($res) {
			echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
	}
	//商家管理订单
	public function doPageCusorders(){
		global $_W, $_GPC;
		$openid_id=pdo_get('zh_gjw_register',array('uniacid'=>$_W['uniacid'],'openid'=>$_GPC['openid']));
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=4;
      	$where=' WHERE  a.uniacid=:uniacid and a.state=:state and a.type=:type and b.phone=:phone ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':state']=$_GPC['state'];
	    $data[':type']=$_GPC['mtype'];
	    $data[':phone']=$openid_id['phone'];
     	if ($_GPC['mtype']==1) {
	    	$sql="SELECT a.*,b.dbname FROM ".tablename('zh_gjw_orders') . " a"  . " left join " . tablename("zh_gjw_dbpublish") . " b on a.p_id=b.id ".$where." ORDER BY a.time desc";
  			$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_orders') . " a"  . " left join " . tablename("zh_gjw_dbpublish") . " b on a.p_id=b.id ".$where." ORDER BY a.time desc",$data);
	    }
	    if ($_GPC['mtype']==2) {
	    	$sql="SELECT a.*,b.title FROM ".tablename('zh_gjw_orders') . " a"  . " left join " . tablename("zh_gjw_shotpublish") . " b on a.p_id=b.id ".$where." ORDER BY a.time desc";
  			$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_orders') . " a"  . " left join " . tablename("zh_gjw_shotpublish") . " b on a.p_id=b.id ".$where." ORDER BY a.time desc",$data);
	    }
	    if ($_GPC['mtype']==3) {
	    	$sql="SELECT a.*,b.title FROM ".tablename('zh_gjw_orders') . " a"  . " left join " . tablename("zh_gjw_marketpublish") . " b on a.p_id=b.id ".$where." ORDER BY a.time desc";
  			$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_orders') . " a"  . " left join " . tablename("zh_gjw_marketpublish") . " b on a.p_id=b.id ".$where." ORDER BY a.time desc",$data);
	    }
        if ($_GPC['mtype']==4) {
          $sql="SELECT a.*,b.title FROM ".tablename('zh_gjw_orders') . " a"  . " left join " . tablename("zh_gjw_storepublish") . " b on a.p_id=b.id ".$where." ORDER BY a.time desc";
          $total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_orders') . " a"  . " left join " . tablename("zh_gjw_storepublish") . " b on a.p_id=b.id ".$where." ORDER BY a.time desc",$data);
        }
	    //$sql="SELECT * FROM ".tablename('zh_gjw_orders') .$where." ORDER BY time desc";
    	//$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_orders').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		for($i=0; $i <count($res) ; $i++){
			if ($res[$i]['type']==1) {
				$dbimg=pdo_get('zh_gjw_dbpublish',array('id'=>$res[$i]['p_id']));
				$res[$i]['videoimg']=$dbimg['videoimg'];
			}
			if ($res[$i]['type']==2) {
				$shotimg=pdo_get('zh_gjw_shotpublish',array('id'=>$res[$i]['p_id']));
				$imgs=explode(',', $shotimg['img']);
				$res[$i]['videoimg']=$imgs[0];
			}
			if ($res[$i]['type']==3) {
				$marketimg=pdo_get('zh_gjw_marketpublish',array('id'=>$res[$i]['p_id']));
				$res[$i]['videoimg']=explode(',', $marketimg['img'])[0];
			}
			if ($res[$i]['type']==4) {
				$storeimg=pdo_get('zh_gjw_storepublish',array('id'=>$res[$i]['p_id']));
				$res[$i]['videoimg']=explode(',', $storeimg['img'])[0];
			}
		}
		if ($res) {
			echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
	}

	//商家后台点击发货
	public function doPageCusfh(){
		global $_W, $_GPC;
		$res = pdo_update('zh_gjw_orders', array('state' =>3,'exformid' =>$_GPC['formid'],'excompany' =>$_GPC['excompany'],'exordernum' =>$_GPC['exordernum'],'excompanys' =>$_GPC['excompanys'],'exordernums' =>$_GPC['exordernums'],'extime'=>date('Y-m-d H:i:s')), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		if ($res) {
			/*function getaccess_token($_W){
                $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
                $appid=$res['appid'];
                $secret=$res['appsecret'];
                $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL,$url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                $data = curl_exec($ch);
                curl_close($ch);
                $data = json_decode($data,true);
                return $data['access_token'];
            }*/
            function set_msg($_W,$_GPC){
                  //$access_token = getaccess_token($_W);
				  $orderid=pdo_get('zh_gjw_orders',array('uniacid'=>$_W['uniacid'],'id'=>$_GPC['res_id']));
				  if ($orderid['excompany']=='undefined' || $orderid['excompany']==null) {
				  	$orderid['excompany']=$orderid['excompanys'];
				  }
				  	if ($orderid['type']==1) {
						$dbimg=pdo_get('zh_gjw_dbpublish',array('id'=>$orderid['p_id']));
						$orderid['title']=$dbimg['dbname'];
					}
					if ($orderid['type']==2) {
						$shotimg=pdo_get('zh_gjw_shotpublish',array('id'=>$orderid['p_id']));
						$orderid['title']=$shotimg['title'];
					}
					if ($orderid['type']==3) {
						$marketimg=pdo_get('zh_gjw_marketpublish',array('id'=>$orderid['p_id']));
						$orderid['title']=$marketimg['title'];
					}
					if ($orderid['type']==4) {
						$storeimg=pdo_get('zh_gjw_storepublish',array('id'=>$orderid['p_id']));
						$orderid['title']=$storeimg['title'];
					}
				  $openid_id=pdo_get('zh_gjw_register',array('uniacid'=>$_W['uniacid'],'id'=>$orderid['u_id']));
				  $cusname=pdo_get('zh_gjw_cusmanage',array('uniacid'=>$_W['uniacid'],'openid'=>$openid_id['openid']));
                  $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
                  $formwork ='{
                      "touser": "'.$openid_id["openid"].'",
                      "template_id": "'.$ress["templeidoo"].'",
                      "form_id":"'.$orderid['formid'].'",
                      "data": {
                          "keyword1": {
                              "value": "'.$orderid["excompany"].'",
                              "color": "#173177"
                          },
                          "keyword2": {
                              "value":"'.$orderid["extime"].'",
                              "color": "#173177"
                          },
                          "keyword3": {
                              "value":"'.$orderid["paytime"].'",
                              "color": "#173177"
                          },
                          "keyword4": {
                              "value":"'.$orderid["title"].'",
                              "color": "#173177"
                          },
                          "keyword5": {
                              "value":"'.$cusname["cusname"].'",
                              "color": "#173177"
                          },
                          "keyword6": {
                              "value":"'.$orderid["ordernum"].'",
                              "color": "#173177"
                          },
                          "keyword7": {
                              "value":"'.$orderid["id"].'",
                              "color": "#173177"
                          },
                          "keyword8": {
                              "value":"'.$orderid["exordernums"].'",
                              "color": "#173177"
                          },
                          "keyword9": {
                              "value":"'.$orderid["exordernum"].'",
                              "color": "#173177"
                          },
                          "keyword10": {
                              "value":"已发货(“快递100小助手”小程序中查询)",
                              "color": "#173177"
                          }
                      }  
                  }';
                  $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
                  $ch = curl_init();
                  curl_setopt($ch, CURLOPT_URL,$url);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                  curl_setopt($ch, CURLOPT_POST,1);
                  curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
                  $data = curl_exec($ch);
                  curl_close($ch);
                 return $data;
            }
            set_msg($_W,$_GPC);
			echo json_encode(array('msg'=>'成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'失败','code'=>'500'),320);exit();
	}
	//用户点击收货
	public function doPageUsersh(){
		global $_W, $_GPC;
      	function getLevelu($members, $xf_money)
        {
            for ($i = 0; $i < count($members); $i++) {
                if ($xf_money >= $members[$i]['money']) {
                    return $members[$i]['name'];
                }
                if ($xf_money < $members[$i]['money'] && $xf_money > $members[$i + 1]['money']) {
                    return $members[$i + 1]['name'];
                }
            }
        }
		$res = pdo_update('zh_gjw_orders', array('state' =>4), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		if ($res) {
			$cus=pdo_get('zh_gjw_orders',array('id'=>$_GPC['res_id']));
			$totalmoney=pdo_get('zh_gjw_orders', array('cus_id' => $cus['cus_id'], 'uniacid' => $_W['uniacid'],'state'=>4), array('sum(ofees) as total_money'));
	        $store = pdo_getall('zh_gjw_storegrade', array('uniacid' => $_W['uniacid']), array(), '', 'money DESC');
	        $storename = getLevelu($store, $totalmoney['total_money']);
	        if ($storename) {
	            pdo_update('zh_gjw_cusmanage', array('level_name' => $storename), array('id' => $cus['cus_id']));
	        }
			echo json_encode(array('msg'=>'成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'失败','code'=>'500'),320);exit();
	}
	/**
	*订单评论
	*/
	public function doPageOrderassess(){
		global $_GPC, $_W;
		$shset=pdo_get('zh_gjw_shset',array('uniacid'=>$_W['uniacid']));
		$openid_id=pdo_get('zh_gjw_register',array('uniacid'=>$_W['uniacid'],'openid'=>$_GPC['openid']));
		$data['content']=$_GPC['content'];
		$data['u_id']=$openid_id['id'];
		$data['p_id']=$_GPC['p_id'];
		$data['formid']=$_GPC['formid'];
		$data['star']=$_GPC['star'];
		$data['desstar']=$_GPC['desstar'];
		$data['speedstar']=$_GPC['speedstar'];
		$data['pricetag']=$_GPC['pricetag'];
		$data['speedtag']=$_GPC['speedtag'];
		$data['packtag']=$_GPC['packtag'];
		$data['babytag']=$_GPC['babytag'];
		$data['confidetag']=$_GPC['confidetag'];
		$data['img']=$_GPC['img'];
		if ($shset['orderassessshset']==0) {
			$data['state']=2;
		}elseif($shset['orderassessshset']==1){
			$data['state']=1;
		}
		$data['uniacid']=$_W['uniacid'];
		$data['time']=date('Y-m-d H:i:s',time());
		$res=pdo_insert('zh_gjw_orderassess',$data);
		if (empty($res)) {
			echo json_encode(array('msg'=>'评论失败','code'=>'500'),320);exit();
		}
		echo json_encode(array('msg'=>'评论成功','code'=>'200'),320);exit();
	}
	/**
	*订单评论否/是
	*/
	public function doPageOrderassessis(){
		global $_GPC, $_W;
		$openid_id=pdo_get('zh_gjw_register',array('uniacid'=>$_W['uniacid'],'openid'=>$_GPC['openid']));
		$is=pdo_get('zh_gjw_orderassess',array('uniacid'=>$_W['uniacid'],'u_id'=>$openid_id['id'],'p_id'=>$_GPC['p_id']));
		if ($is) {
			echo json_encode(array('msg'=>'评论过','code'=>'200'),320);exit();
		}
		echo json_encode(array('msg'=>'未评论过','code'=>'500'),320);exit();
	}
	/**
	*订单软删除
	*/
	public function doPageOrderdelete(){
		global $_GPC, $_W;
    	$res=pdo_update('zh_gjw_orders', array('udelete' =>1),array('id'=>$_GPC['id']));
		if ($res) {
			echo json_encode(array('msg'=>'删除成功','code'=>'200'),320);exit();
		}
		echo json_encode(array('msg'=>'删除失败','code'=>'500'),320);exit();
	}
	//提现时密码判断
	public function doPageCashpassword(){
		global $_GPC, $_W;
		$password=pdo_get('zh_gjw_cusmanage',array('uniacid'=>$_W['uniacid'],'openid'=>$_GPC['openid']));
		if ($password['password']==$_GPC['password']) {
			echo json_encode(array('msg'=>'成功','code'=>'200'),320);exit();
		}
		echo json_encode(array('msg'=>'失败','code'=>'500'),320);exit();
	}
	//提现提交
	public function doPageCashformsub(){
		global $_GPC, $_W;
		$user=pdo_get('zh_gjw_register',array('uniacid'=>$_W['uniacid'],'openid'=>$_GPC['openid']));
		$data['openid']=$_GPC['openid'];
		$data['formid']=$_GPC['formid'];
		$data['u_id']=$user['id'];
		$data['realname']=$user['username'];
		$data['cash']=$_GPC['cash'];
		$data['type']=$_GPC['types']+1;
		$data['zfb']=$_GPC['zfb'];
		$data['yhk']=$_GPC['yhk'];
		$data['phone']=$_GPC['phone'];
		$data['wechat']=$_GPC['wechat'];
		$data['yhname']=$_GPC['yhname'];
		$data['zhname']=$_GPC['zhname'];
		$data['name']=$_GPC['name'];
		$data['mode']=$_GPC['mode'];
		$data['realcash']=$_GPC['realcash'];
		$data['state']=1;
		$data['uniacid']=$_W['uniacid'];
		$data['applytime']=date('Y-m-d H:i:s',time());
		$res=pdo_insert('zh_gjw_cashlist',$data);
		$res_id=pdo_insertid();
		if ($res) {
			/*function getaccess_token($_W){
                $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
                $appid=$res['appid'];
                $secret=$res['appsecret'];
                $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL,$url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                $data = curl_exec($ch);
                curl_close($ch);
                $data = json_decode($data,true);
                return $data['access_token'];
            }*/
            function set_msg($_W,$res_id){
                  //$access_token = getaccess_token($_W);
                  $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
                  $cashlist=pdo_get('zh_gjw_cashlist',array('id'=>$res_id));
                  $openid=pdo_get('zh_gjw_register',array('id'=>$cashlist['u_id']));
                  $formwork ='{
                      "touser": "'.$openid["openid"].'",
                      "template_id": "'.$ress["templeidapply"].'",
                      "form_id":"'.$cashlist['formid'].'",
                      "data": {
                          "keyword1": {
                              "value": "'.round($cashlist['realcash'],2).'",
                              "color": "#173177"
                          },
                          "keyword2": {
                              "value":"'.$cashlist['applytime'].'",
                              "color": "#173177"
                          },
                          "keyword3": {
                              "value":"提现申请",
                              "color": "#173177"
                          }
                      }  
                  }';
                  $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
                  $ch = curl_init();
                  curl_setopt($ch, CURLOPT_URL,$url);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                  curl_setopt($ch, CURLOPT_POST,1);
                  curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
                  $data = curl_exec($ch);
                  curl_close($ch);
                 return $data;
            }
            // set_msg($_W,$res_id);
			echo json_encode(array('msg'=>'成功','code'=>'200'),320);exit();
		}
		echo json_encode(array('msg'=>'失败','code'=>'500'),320);exit();
	}
	//商家后台订单详情页
	public function doPageCodetail(){
		global $_GPC, $_W;
		$order=pdo_get('zh_gjw_orders',array('uniacid'=>$_W['uniacid'],'id'=>$_GPC['id']));
		if ($order) {
			if ($order['type']==1) {
				$dbimg=pdo_get('zh_gjw_dbpublish',array('id'=>$order['p_id']));
				$order['videoimg']=$dbimg['videoimg'];
				$order['title']=$dbimg['dbname'];
				$order['exfee']=$dbimg['exfee'];
				//$order['total']=$order['ofees']-$dbimg['exfee'];
				$order['total'] = bcsub($order['ofees'], $dbimg['exfee'],2);
			}
			if ($order['type']==2) {
				$shotimg=pdo_get('zh_gjw_shotpublish',array('id'=>$order['p_id']));
				$order['videoimg']=$shotimg['img'];
				$order['title']=$shotimg['title'];
				$order['exfee']=$shotimg['exfee'];
				//$order['total']=$order['ofees']-$shotimg['exfee'];
				$order['total'] = bcsub($order['ofees'], $dbimg['exfee'],2);
			}
			if ($order['type']==3) {
				$marketimg=pdo_get('zh_gjw_marketpublish',array('id'=>$order['p_id']));
				$order['videoimg']=$marketimg['img'];
				$order['title']=$marketimg['title'];
				$order['exfee']=$marketimg['exfee'];
				//$order['total']=$order['ofees']-$marketimg['exfee'];
				$order['total'] = bcsub($order['ofees'], $dbimg['exfee'],2);
			}
			echo json_encode(array('msg'=>'成功','code'=>'200','res'=>$order),320);exit();
		}
		echo json_encode(array('msg'=>'失败','code'=>'500'),320);exit();
	}
	//订单评论查看
	public function doPageLookassess(){
		global $_GPC, $_W;
		$ass=pdo_getall('zh_gjw_orderassess',array('uniacid'=>$_W['uniacid'],'p_id'=>$_GPC['a_id']));
		if ($ass) {
			echo json_encode(array('msg'=>'成功','code'=>'200','res'=>$ass),320);exit();
		}
		echo json_encode(array('msg'=>'失败','code'=>'500'),320);exit();
	}

	//商家支付之期判断
	public function doPageCuspaydate(){
		global $_GPC, $_W;
      	if($_GPC['admin']){
			$cus=pdo_get('zh_gjw_cusmanage',array('uniacid'=>$_W['uniacid'],'phone'=>$_GPC['admin']));
        }else{
			$cus=pdo_get('zh_gjw_cusmanage',array('uniacid'=>$_W['uniacid'],'openid'=>$_GPC['openid']));
        }
		if ($cus) {
			if(time()-strtotime($cus['paytime'])>365*86400){
				echo json_encode(array('msg'=>'过期了,要缴费了','code'=>'201'),320);exit();
			}else{
				echo json_encode(array('msg'=>'还在一年使用之期内，不需要缴费，通过','code'=>'200'),320);exit();
			}
		}
		echo json_encode(array('msg'=>'不存在','code'=>'500'),320);exit();
	}
	//商家过期补费
	public function doPageCuspayagain(){
		global $_W, $_GPC;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$res_fee=$_GPC['publishfee'];
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		pdo_update('zh_gjw_cusmanage', array('paycode' =>$out_trade_no), array('openid' =>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$root=$_W['siteroot']; 
		$total_fee =$res_fee;
		if($total_fee>0)
		{
			$body = "商家补费一年";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
		echo json_encode($return);
	}
  
	//商家补费成功改变状态
	public function doPageCuspaydatesuccess(){
		global $_W, $_GPC;
		$cusmoney=pdo_get('zh_gjw_cusmoney',array('uniacid'=>$_W['uniacid']));
    	$type=pdo_get('zh_gjw_cusmanage',array('openid'=>$_GPC['openid']));
		if ($type==1) {
    		$payfee=$cusmoney['dpublishfee']+$type['payfee'];
			$res = pdo_update('zh_gjw_cusmanage', array('payfee' => $payfee,'paytime' =>date('Y-m-d H:i:s',time())), array('openid' =>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		}else{
    		$payfee=$cusmoney['publishfee']+$type['payfee'];
			$res = pdo_update('zh_gjw_cusmanage', array('payfee' => $payfee,'paytime' =>date('Y-m-d H:i:s',time())), array('openid' =>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		}
		if ($res) {
			echo json_encode(array('msg'=>'嗨','code'=>'200'),320);exit();
		}
		echo json_encode(array('msg'=>'错','code'=>'500'),320);exit();
	}
	//余额统计
	public function doPageBalance(){
		global $_W, $_GPC;
		/*$dbm=0;
		$shotm=0;
		$marketm=0;*/
      	if($_GPC['phone']){
			$user=pdo_get('zh_gjw_register',array('uniacid'=>$_W['uniacid'],'phone' =>$_GPC['phone']));
        }else{
        	$user=pdo_get('zh_gjw_register',array('uniacid'=>$_W['uniacid'],'openid' =>$_GPC['openid']));
        }
        $cus=pdo_get('zh_gjw_cusmanage',array('uniacid'=>$_W['uniacid'],'openid' =>$user['openid']));

		$totalmoney=pdo_get('zh_gjw_orders', array('cus_id' => $cus['id'], 'uniacid' => $_W['uniacid'],'state'=>4), array('sum(ofees) as total_money'));
		$balance=pdo_get('zh_gjw_balance', array('c_id' => $cus['id'], 'uniacid' => $_W['uniacid'],'sysbzj'=>1), array('sum(fee) as total_money'));
      	$allmoney=$totalmoney['total_money']+$balance['total_money'];
		/*$db=pdo_getall('zh_gjw_orders',array('uniacid'=>$_W['uniacid'],'u_id' =>$user['id'],'state'=>4,'type'=>1));
		$shot=pdo_getall('zh_gjw_orders',array('uniacid'=>$_W['uniacid'],'u_id' =>$user['id'],'state'=>4,'type'=>2));
		$market=pdo_getall('zh_gjw_orders',array('uniacid'=>$_W['uniacid'],'u_id' =>$user['id'],'state'=>4,'type'=>3));
			// echo json_encode(array('msg'=>'成功','code'=>'200','shot'=>$shot),320);exit();
		if ($db) {
			for ($i=0; $i <count($db) ; $i++) { 
				$dbm+=$db[$i]['ofees'];
			}
		}
		if ($shot) {
			for ($i=0; $i <count($shot) ; $i++) { 
				//押金
				$shotmoney=pdo_get('zh_gjw_shotpublish',array('uniacid'=>$_W['uniacid'],'id' =>$shot[$i]['p_id']));
				//订单成交金额
				$shotm+=$shot[$i]['ofees']+$shotmoney['shotmoney']*0.1;
			}
		}
		if ($market) {
			for ($i=0; $i <count($market) ; $i++) { 
				$marketmoney=pdo_get('zh_gjw_marketpublish',array('uniacid'=>$_W['uniacid'],'id' =>$market[$i]['p_id']));
				$marketm+=$market[$i]['ofees']+$marketmoney['lmoney']*0.1;
			}
		}
		$allmoney=$dbm+$shotm+$marketm;*/
		if($allmoney>0){
			/*$cash=pdo_getall('zh_gjw_cashlist',array('uniacid'=>$_W['uniacid'],'u_id' =>$user['id']));
			if ($cash) {
				for ($i=0; $i <count($cash) ; $i++) { 
					$allmoney-=$cash[$i]['cash'];
				}
			}*/
          	$cash=pdo_get('zh_gjw_cashlist', array('u_id' => $user['id'], 'uniacid' => $_W['uniacid']), array('sum(cash) as total_money'));
          	$cashs=pdo_get('zh_gjw_cashlist', array('u_id' => $user['id'], 'uniacid' => $_W['uniacid'],'state'=>3), array('sum(cash) as total_money'));
          	$allmoney=$allmoney-$cash['total_money']+$cashs['total_money'];
			echo json_encode(array('msg'=>'成功','code'=>'200','allmoney'=>$allmoney),320);exit();
		}
		echo json_encode(array('msg'=>'没有','code'=>'500'),320);exit();
	}
	//提现设置
	public function doPageCashset(){
		global $_W, $_GPC;
		$res=pdo_get('zh_gjw_cashset',array('uniacid'=>$_W['uniacid']));
		if($res){
			echo json_encode(array('msg'=>'成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'失败','code'=>'500'),320);exit();
	}
	//修改资料
	public function doPageEditcus(){
		global $_W, $_GPC;
		$data['bannerimg']=$_GPC['bannerimg'];
    	$data['latlng']=$_GPC['latlng'];
    	$data['storedetail']=$_GPC['storedetail'];
      	
      	if($_GPC['phone']){
			$res=pdo_update('zh_gjw_cusmanage', $data, array('phone' =>$_GPC['phone']));
        }else{
			$res=pdo_update('zh_gjw_cusmanage', $data, array('openid' =>$_GPC['openid']));
        }
		if($res){
			echo json_encode(array('msg'=>'成功','code'=>'200'),320);exit();
		}
		echo json_encode(array('msg'=>'失败','code'=>'500'),320);exit();
	}
	//是否修改资料
	public function doPageEditcusis(){
		global $_W, $_GPC;
      	if($_GPC['phone']){
			$res=pdo_get('zh_gjw_cusmanage', array('phone' =>$_GPC['phone']));
        }else{
			$res=pdo_get('zh_gjw_cusmanage', array('openid' =>$_GPC['openid']));
        }
		if($res['bannerimg']){
			echo json_encode(array('msg'=>'存在','code'=>'200'),320);exit();
		}
		echo json_encode(array('msg'=>'不存在','code'=>'500'),320);exit();
	}
  
	//微拍置顶
	public function doPageShottoppay(){
		global $_GPC, $_W;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		$root=$_W['siteroot']; 
    	$primoney=pdo_get('zh_gjw_shotmoney',array('uniacid'=>$_W['uniacid']));
		$total_fee =$primoney['topfee'];
		if($total_fee>0)
		{
			$body = "微拍置顶";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
		echo json_encode($return);
	}
	//微拍置顶topfee+1
	public function doPageShottopsuccess(){
		global $_W, $_GPC;
		file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=GetGradeshotp&m=zh_gjw&order_id=" . $_GPC['id']);//修改等级
		$topfee=pdo_get('zh_gjw_shotpublish',array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		$topfee['topfee']=$topfee['topfee']+1;
		$res =	pdo_update('zh_gjw_shotpublish', array('topfee' =>$topfee['topfee'],'uptime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if ($res) {
          	
			if($_GPC['openid']&&$_GPC['top']==1){
				$datas['openid']=$_GPC['openid'];
				$datas['type']=10;
				$datas['uniacid']=$_W['uniacid'];
				$datas['number']=1;
				$datas['sjc']=time();
				$datas['time']=date('Y-m-d H:i:s',time());
				pdo_insert('zh_gjw_repucost',$datas);
			}else{
                $shotmoney=pdo_get('zh_gjw_shotmoney',array('uniacid'=>$_W['uniacid']));
                $data['p_id']=$_GPC['id'];
                $data['fee']=$shotmoney['topfee'];
                $data['uniacid']=$_W['uniacid'];
                $data['time']=date('Y-m-d H:i:s',time());
                if ($shotmoney['topfee']>0) {
                    pdo_insert('zh_gjw_shotorder',$data);
                }
            }
			echo json_encode(array('msg'=>'置顶成功','code'=>'200','res'=>$res),320);exit();
		}else{
			echo json_encode(array('msg'=>'置顶失败','code'=>'500'),320);exit();
		}
	}
	//微拍推荐
	public function doPageShotuppay(){
		global $_GPC, $_W;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		$root=$_W['siteroot']; 
    	$primoney=pdo_get('zh_gjw_shotmoney',array('uniacid'=>$_W['uniacid']));
		$total_fee =$primoney['upfee'];
		if($total_fee>0)
		{
			$body = "微拍推荐";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
		echo json_encode($return);
	}
	//微拍推荐upfee+1
	public function doPageShotupsuccess(){
		global $_W, $_GPC;
		file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=GetGradeshotp&m=zh_gjw&order_id=" . $_GPC['id']);//修改等级
		$upfee=pdo_get('zh_gjw_shotpublish',array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		$res =	pdo_update('zh_gjw_shotpublish', array('upfee' =>1,'uptime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if ($res) {
			if($_GPC['openid']&&$_GPC['up']==1){
				$datas['openid']=$_GPC['openid'];
				$datas['type']=9;
				$datas['uniacid']=$_W['uniacid'];
				$datas['number']=1;
				$datas['sjc']=time();
				$datas['time']=date('Y-m-d H:i:s',time());
				pdo_insert('zh_gjw_repucost',$datas);
			}else{
                $shotmoney=pdo_get('zh_gjw_shotmoney',array('uniacid'=>$_W['uniacid']));
                $data['p_id']=$_GPC['id'];
                $data['fee']=$shotmoney['upfee'];
                $data['uniacid']=$_W['uniacid'];
                $data['time']=date('Y-m-d H:i:s',time());
                if ($shotmoney['upfee']>0) {
                    pdo_insert('zh_gjw_shotorder',$data);
                }
            }
			echo json_encode(array('msg'=>'推荐成功','code'=>'200','res'=>$res),320);exit();
		}else{
			echo json_encode(array('msg'=>'推荐失败','code'=>'500'),320);exit();
		}
	}

	//地摊置顶
	public function doPageMarkettoppay(){
		global $_GPC, $_W;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		$root=$_W['siteroot']; 
    	$primoney=pdo_get('zh_gjw_marketmoney',array('uniacid'=>$_W['uniacid']));
		$total_fee =$primoney['topfee'];
		if($total_fee>0)
		{
			$body = "地摊置顶";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
		echo json_encode($return);
	}
	//地摊置顶topfee+1
	public function doPageMarkettopsuccess(){
		global $_W, $_GPC;
		file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=GetGrademarketp&m=zh_gjw&order_id=" . $_GPC['id']);//修改等级
		$topfee=pdo_get('zh_gjw_marketpublish',array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		$topfee['topfee']=$topfee['topfee']+1;
		$res =	pdo_update('zh_gjw_marketpublish', array('topfee' =>$topfee['topfee'],'uptime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if ($res) {
    		
			if($_GPC['openid']&&$_GPC['top']==1){
				$datas['openid']=$_GPC['openid'];
				$datas['type']=12;
				$datas['uniacid']=$_W['uniacid'];
				$datas['number']=1;
				$datas['sjc']=time();
				$datas['time']=date('Y-m-d H:i:s',time());
				pdo_insert('zh_gjw_repucost',$datas);
			}else{
                $marketmoney=pdo_get('zh_gjw_marketmoney',array('uniacid'=>$_W['uniacid']));
                $data['p_id']=$_GPC['id'];
                $data['fee']=$marketmoney['topfee'];
                $data['uniacid']=$_W['uniacid'];
                $data['time']=date('Y-m-d H:i:s',time());
                if ($marketmoney['topfee']>0) {
                    pdo_insert('zh_gjw_marketorder',$data);
                }
            }
			echo json_encode(array('msg'=>'置顶成功','code'=>'200','res'=>$res),320);exit();
		}else{
			echo json_encode(array('msg'=>'置顶失败','code'=>'500'),320);exit();
		}
	}
	//地摊推荐
	public function doPageMarketuppay(){
		global $_GPC, $_W;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		$root=$_W['siteroot']; 
    	$primoney=pdo_get('zh_gjw_marketmoney',array('uniacid'=>$_W['uniacid']));
		$total_fee =$primoney['upfee'];
		if($total_fee>0)
		{
			$body = "抖宝推荐";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
		echo json_encode($return);
	}
	//地摊推荐upfee+1
	public function doPageMarketupsuccess(){
		global $_W, $_GPC;
		file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=GetGrademarketp&m=zh_gjw&order_id=" . $_GPC['id']);//修改等级
		$upfee=pdo_get('zh_gjw_marketpublish',array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		$res =	pdo_update('zh_gjw_marketpublish', array('upfee' =>1,'uptime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if ($res) {
    		
			if($_GPC['openid']&&$_GPC['up']==1){
				$datas['openid']=$_GPC['openid'];
				$datas['type']=11;
				$datas['uniacid']=$_W['uniacid'];
				$datas['number']=1;
				$datas['sjc']=time();
				$datas['time']=date('Y-m-d H:i:s',time());
				pdo_insert('zh_gjw_repucost',$datas);
			}else{
	    		$marketmoney=pdo_get('zh_gjw_marketmoney',array('uniacid'=>$_W['uniacid']));
				$data['p_id']=$_GPC['id'];
				$data['fee']=$marketmoney['upfee'];
				$data['uniacid']=$_W['uniacid'];
				$data['time']=date('Y-m-d H:i:s',time());
				if ($marketmoney['upfee']>0) {
					pdo_insert('zh_gjw_marketorder',$data);
				}
			}
			echo json_encode(array('msg'=>'推荐成功','code'=>'200','res'=>$res),320);exit();
		}else{
			echo json_encode(array('msg'=>'推荐失败','code'=>'500'),320);exit();
		}
	}
  
	//地摊出价者管理
	public function doPageOutall(){
		global $_W, $_GPC;
		$res=pdo_fetchall("SELECT a.*,b.username,b.phone,b.avatar FROM ".tablename('zh_gjw_marketbuy'). " a left join " . tablename("zh_gjw_register") . " b on a.u_id=b.id WHERE a.uniacid=:uniacid and a.market_id=:market_id ORDER BY a.time desc", array(':uniacid'=>$_W['uniacid'],':market_id'=>$_GPC['id']));
		if ($res) {
			echo json_encode(array('msg'=>'成功','code'=>'200','res'=>$res),320);exit();
		}else{
			echo json_encode(array('msg'=>'失败','code'=>'500'),320);exit();
		}
	}
  
	//地摊出价者被告知
	public function doPageOutsole(){
		global $_W, $_GPC;
		$exit=pdo_get('zh_gjw_marketbuy',array('id' =>$_GPC['id']));
		$all=pdo_get('zh_gjw_marketbuy',array('uniacid'=>$_W['uniacid'],'market_id' =>$exit['market_id'],'tole' =>1));
		if ($all) {
			echo json_encode(array('msg'=>'失败','code'=>'500'),320);exit();
		}
		$res =	pdo_update('zh_gjw_marketbuy', array('tole' =>1), array('id' =>$_GPC['id']));
		if ($res) {
			echo json_encode(array('msg'=>'成功','code'=>'200'),320);exit();
		}else{
			echo json_encode(array('msg'=>'失败','code'=>'500'),320);exit();
		}
	}
  
	//我的竞拍待支付
	public function doPageMymarkettopays(){
		global $_W,$_GPC;
		$arr=array();
		$openid=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$res=pdo_fetchall("SELECT a.*,b.img,b.totime,b.title,b.view,b.agree,b.video,b.phone,b.lmoney,b.exfee,b.time as markettime FROM " . tablename('zh_gjw_marketbuy'). " a"  . " left join " . tablename("zh_gjw_marketpublish") . " b on a.market_id=b.id WHERE  a.u_id=:u_id and a.uniacid=:uniacid and a.pay=:pay and a.tole=:tole", array(':u_id'=>$openid['id'],':uniacid'=>$_W['uniacid'],':pay'=>0,':tole'=>1));
		for ($i=0; $i <count($res) ; $i++) { 
			$cusname=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone'],'uniacid'=>$_W['uniacid']));
			if ($cusname) {
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $cusname['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['reputation']=$cusname['reputation'];
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['cusname']=$cusname['cusname'];
				$res[$i]['level_name']=$cusname['level_name'];
				$res[$i]['storeimg']=$cusname['storeimg'];
			}else{
				$res[$i]['cusname']='';
				$res[$i]['storeimg']='';
				$res[$i]['level_name']='';
			}
			$res[$i]['totimesjc']=strtotime($res[$i]['markettime'])+86400*5;
          	$ttotime=strtotime($res[$i]['markettime'])+86400*7;
			if (time()<$ttotime && $res[$i]['pay']!=1) {
				array_push($arr,$res[$i]);
			}
		}
      	if (empty($res)) {
			echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
		}else{
			echo json_encode(array('msg'=>'找到啦','code'=>'200','res'=>$arr),320);exit();
		}
	}
  
	//我的地摊竞拍ing
	public function doPageMymarketings(){
		global $_W,$_GPC;
		$arr=array();
		$openid=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$res=pdo_fetchall("SELECT * FROM ".tablename('zh_gjw_marketpublish') ." WHERE phone=:phone and time+INTERVAL 120 HOUR>=FROM_UNIXTIME(".time().") and NOW()>time ORDER BY time desc", array(':phone'=>$openid['phone']));
      	for ($i=0; $i <count($res) ; $i++) { 
      		$res[$i]['totime']=date('Y-m-d H:i:s',strtotime($res[$i]['time'])+86400*5);
			$exit[$i]=pdo_get('zh_gjw_marketbuy',array('market_id'=>$res[$i]['id']));
			if ($exit[$i]) {
				array_push($arr,$res[$i]);
			}
		}
		if (empty($arr)) {
			echo json_encode(array('msg'=>'暂无数据','code'=>'500'),320);exit();
		}else{
			echo json_encode(array('msg'=>'找到啦','code'=>'200','res'=>$arr),320);exit();
		}
	}
  	
	//商店费用
    public function doPageStoremoney(){
    	global $_GPC,$_W;
    	$marketmoney=pdo_get('zh_gjw_storemoney',array('uniacid'=>$_W['uniacid']));
    	if (empty($marketmoney)) {
    		echo json_encode(array('msg'=>'查询失败','code'=>'500'),320);exit();
    	}elseif($marketmoney){
    		echo json_encode(array('msg'=>'查询成功','code'=>'200','res'=>$marketmoney),320);exit();
    	}
    }
  	//发布商店
    public function doPageStorepublish(){
    	global $_GPC,$_W;
		$data['formid']=$_GPC['formid'];
		$data['title']=$_GPC['title'];
		$data['phone']=$_GPC['phone'];
		$data['price']=$_GPC['price'];
		$data['nums']=$_GPC['nums'];
		$data['co_id']=$_GPC['co_id'];
		$data['ct_id']=$_GPC['ct_id'];
		$data['cth_id']=$_GPC['cth_id'];
		$data['exfee']=$_GPC['exfee'];
		$data['detail']=$_GPC['detail'];
		$data['img']=$_GPC['img'];
		$data['video']=$_GPC['videoimgtemp'];
		$data['state']=1;
		$data['uniacid']=$_W['uniacid'];
		$data['time']=date('Y-m-d H:i:s',time());
		$res=pdo_insert('zh_gjw_storepublish',$data);
		$res_id=pdo_insertid();
    	if ($res) {
    		echo json_encode(array('msg'=>'记录成功','code'=>'200','res'=>$res,'res_id'=>$res_id),320);exit();
		}else{
			echo json_encode(array('msg'=>'记录失败','code'=>'500'),320);exit();
		}
    }
    //商店发布支付
	public function doPageStorepay(){
		global $_W, $_GPC;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$res_fee=0;
    	$shset=pdo_get('zh_gjw_shset',array('uniacid'=>$_W['uniacid']));
    	if ($shset['storeshset']==1) {
	    	if ($_GPC['upstate']==1) {
	    		if($_GPC['publishfee']>0){
	    			$res_fee=$_GPC['publishfee']+$_GPC['upfee'];
	    		}else{
	    			$res_fee=$_GPC['upfee'];
	    		}
			}else{
				if($_GPC['publishfee']>0){
	    			$res_fee=$_GPC['publishfee'];
	    		}else{
	    			$res_fee=0;
	    		}
			}
    	}elseif ($shset['storeshset']!=1) {
    		if ($_GPC['upstate']==1) {
	    		if($_GPC['publishfee']>0){
	    			$res_fee=$_GPC['publishfee']+$_GPC['upfee'];
	    		}else{
	    			$res_fee=$_GPC['upfee'];
	    		}
			}else{
				if($_GPC['publishfee']>0){
	    			$res_fee=$_GPC['publishfee'];
	    		}else{
	    			$res_fee=0;
	    		}
			}
    	}
    	if ($_GPC['alltype']==12) {
			$res_fee=$res_fee-$_GPC['upfee'];
		}
		if ($_GPC['alltype']==16) {
			$res_fee=$res_fee-$_GPC['publishfee'];
		}
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		pdo_update('zh_gjw_storepublish', array('paycode' =>$out_trade_no), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		$root=$_W['siteroot'];
		$total_fee =$res_fee;
		if($total_fee>0)
		{
			$body = "商城商品发布";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
		echo json_encode($return);
	}
	//商店发布支付成功改变state
	public function doPageStoresuccess(){
		global $_W, $_GPC;
		file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=GetGradestorep&m=zh_gjw&order_id=" . $_GPC['res_id']);//修改等级
		/*function getaccess_token($_W){
          $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
          $appid=$res['appid'];
          $secret=$res['appsecret'];
          $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL,$url);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
          $data = curl_exec($ch);
          curl_close($ch);
          $data = json_decode($data,true);
          return $data['access_token'];
        }*/
        function set_msg($_W,$id){
            //$access_token = getaccess_token($_W);
            $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
            $openid=pdo_get('zh_gjw_storepublish',array('id'=>$id));
            $register=pdo_get('zh_gjw_register',array('phone'=>$openid['phone']));
            $formwork ='{
                "touser": "'.$register["openid"].'",
                "template_id": "'.$ress["templeid"].'",
                "form_id":"'.$openid['formid'].'",
                "data": {
                    "keyword1": {
                        "value": "'.$openid['title'].'",
                        "color": "#173177"
                    },
                    "keyword2": {
                        "value":"商城商品审核通过",
                        "color": "#173177"
                    }
                }  
            }';
            $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL,$url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
            curl_setopt($ch, CURLOPT_POST,1);
            curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
            $data = curl_exec($ch);
            curl_close($ch);
           return $data;
        }
    	$shset=pdo_get('zh_gjw_shset',array('uniacid'=>$_W['uniacid']));
    	$marketmoney=pdo_get('zh_gjw_storemoney',array('uniacid'=>$_W['uniacid']));
    	$marketpublish=pdo_get('zh_gjw_storepublish',array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
    	/*if ($shset['storeshset']==1) {
			if ($_GPC['upstate']==1) {
				if ($marketmoney['publishfee']>0) {
					$allmoney=$marketmoney['publishfee']+$marketmoney['upfee'];
					pdo_update('zh_gjw_storepublish', array('pay' => 1,'upfee' =>1,'payfee'=>$allmoney,'uptime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//有发布费、有推荐、审核开启
				}else{
					$allmoney=$marketmoney['upfee'];
					pdo_update('zh_gjw_storepublish', array('pay' => 1,'upfee' =>1,'payfee'=>$allmoney,'uptime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//无发布费、有推荐、审核开启
				}
			}
			if($_GPC['upstate']!=1){
				if ($marketmoney['publishfee']>0) {
					$allmoney=$marketmoney['publishfee'];
					pdo_update('zh_gjw_storepublish', array('pay' => 1,'payfee'=>$allmoney), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//有发布费、无推荐、审核开启
				}else{
					pdo_update('zh_gjw_storepublish', array('pay' => 1,'payfee'=>0), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//无发布费、无推荐、审核开启
				}
			}
			echo json_encode(array('msg'=>'商城商品发布改变状态成功','code'=>'200','res'=>$res),320);exit();
		}elseif ($shset['storeshset']!=1) {
			if ($_GPC['upstate']==1) {
				if ($marketmoney['publishfee']>0) {
					$allmoney=$marketmoney['publishfee']+$marketmoney['upfee'];
					pdo_update('zh_gjw_storepublish', array('pay' => 1,'upfee' =>1,'payfee'=>$allmoney,'state' => 2,'uptime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//有发布费、有推荐、审核关闭
				}else{
					$allmoney=$marketmoney['upfee'];
					pdo_update('zh_gjw_storepublish', array('pay' => 1,'upfee' =>1,'payfee'=>$allmoney,'state' => 2,'uptime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//无发布费、有推荐、审核关闭
				}
			}
			if($_GPC['upstate']!=1){
				if ($marketmoney['publishfee']>0) {
					$allmoney=$marketmoney['publishfee'];
					pdo_update('zh_gjw_storepublish', array('pay' => 1,'payfee'=>$allmoney,'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//有发布费、无推荐、审核关闭
				}else{
					pdo_update('zh_gjw_storepublish', array('pay' => 1,'state' => 2,'payfee'=>0), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//无发布费、无推荐、审核关闭
				}
			}
			set_msg($_W,$_GPC['res_id']);
			echo json_encode(array('msg'=>'商城商品发布改变状态成功','code'=>'200','res'=>$res),320);exit();
		}*/
      	if ($shset['storeshset']==1) {
			if ($_GPC['upstate']==1) {
				if ($marketmoney['publishfee']>0) {
					$allmoney=$marketmoney['publishfee']+$marketmoney['upfee'];
					if ($_GPC['alltype']==12) {
						pdo_update('zh_gjw_storepublish', array('type' => 12,'pay' => 1,'upfee' =>1,'payfee'=>$marketmoney['publishfee']), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=4;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==16) {
						pdo_update('zh_gjw_storepublish', array('type' => 16,'pay' => 1,'upfee' =>1,'payfee'=>$marketmoney['upfee']), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=4;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==20) {
						pdo_update('zh_gjw_storepublish', array('type' => 20,'pay' => 1,'upfee' =>1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=4;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
						$datas['openid']=$_GPC['openid'];
						$datas['type']=13;
						$datas['uniacid']=$_W['uniacid'];
						$datas['number']=1;
						$datas['sjc']=time();
						$datas['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$datas);
					}
					pdo_update('zh_gjw_storepublish', array('type' => $_GPC['alltype'],'pay' => 1,'upfee' =>1,'payfee'=>$allmoney,'uptime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//有发布费、有推荐、审核开启
				}else{
					$allmoney=$marketmoney['upfee'];
					if ($_GPC['alltype']==10) {
						pdo_update('zh_gjw_storepublish', array('type' => 10,'pay' => 1,'upfee' =>1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=13;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==18) {
						pdo_update('zh_gjw_storepublish', array('type' => 18,'pay' => 1,'upfee' =>1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=13;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					pdo_update('zh_gjw_storepublish', array('type' => $_GPC['alltype'],'pay' => 1,'upfee' =>1,'payfee'=>$allmoney,'uptime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//无发布费、有推荐、审核开启
				}
			}
			if($_GPC['upstate']!=1){
				if ($marketmoney['publishfee']>0) {
					$allmoney=$marketmoney['publishfee'];
					if ($_GPC['alltype']==15) {
						pdo_update('zh_gjw_storepublish', array('type' => 15,'pay' => 1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=4;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==19) {
						pdo_update('zh_gjw_storepublish', array('type' => 19,'pay' => 1), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=4;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					pdo_update('zh_gjw_storepublish', array('type' => $_GPC['alltype'],'pay' => 1,'payfee'=>$allmoney), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//有发布费、无推荐、审核开启
				}else{
					pdo_update('zh_gjw_storepublish', array('type' => $_GPC['alltype'],'pay' => 1,'payfee'=>0), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//无发布费、无推荐、审核开启
				}
			}
			echo json_encode(array('msg'=>'商城商品发布改变状态成功','code'=>'200','res'=>$res),320);exit();
		}elseif ($shset['storeshset']!=1) {
			if ($_GPC['upstate']==1) {
				if ($marketmoney['publishfee']>0) {
					$allmoney=$marketmoney['publishfee']+$marketmoney['upfee'];
					if ($_GPC['alltype']==12) {
						pdo_update('zh_gjw_storepublish', array('type' => 12,'pay' => 1,'upfee' =>1,'payfee'=>$marketmoney['publishfee'],'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=4;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==16) {
						pdo_update('zh_gjw_storepublish', array('type' => 16,'pay' => 1,'upfee' =>1,'payfee'=>$marketmoney['upfee'],'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=4;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==20) {
						pdo_update('zh_gjw_storepublish', array('type' => 20,'pay' => 1,'upfee' =>1,'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=4;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
						$datas['openid']=$_GPC['openid'];
						$datas['type']=13;
						$datas['uniacid']=$_W['uniacid'];
						$datas['number']=1;
						$datas['sjc']=time();
						$datas['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$datas);
					}
					pdo_update('zh_gjw_storepublish', array('type' => $_GPC['alltype'],'pay' => 1,'upfee' =>1,'payfee'=>$allmoney,'state' => 2,'uptime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//有发布费、有推荐、审核关闭
				}else{
					$allmoney=$marketmoney['upfee'];
					if ($_GPC['alltype']==10) {
						pdo_update('zh_gjw_storepublish', array('type' => 10,'pay' => 1,'upfee' =>1,'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=13;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==18) {
						pdo_update('zh_gjw_storepublish', array('type' => 18,'pay' => 1,'upfee' =>1,'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=13;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					pdo_update('zh_gjw_storepublish', array('type' => $_GPC['alltype'],'pay' => 1,'upfee' =>1,'payfee'=>$allmoney,'state' => 2,'uptime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//无发布费、有推荐、审核关闭
				}
			}
			if($_GPC['upstate']!=1){
				if ($marketmoney['publishfee']>0) {
					if ($_GPC['alltype']==15) {
						pdo_update('zh_gjw_storepublish', array('type' => 15,'pay' => 1,'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=4;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					if ($_GPC['alltype']==19) {
						pdo_update('zh_gjw_storepublish', array('type' => 19,'pay' => 1,'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
						$data['openid']=$_GPC['openid'];
						$data['type']=4;
						$data['uniacid']=$_W['uniacid'];
						$data['number']=1;
						$data['sjc']=time();
						$data['time']=date('Y-m-d H:i:s',time());
						pdo_insert('zh_gjw_repucost',$data);
					}
					pdo_update('zh_gjw_storepublish', array('type' => $_GPC['alltype'],'pay' => 1,'payfee'=>$allmoney,'state' => 2), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//有发布费、无推荐、审核关闭
				}else{
					pdo_update('zh_gjw_storepublish', array('type' => $_GPC['alltype'],'pay' => 1,'state' => 2,'payfee'=>0), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));//无发布费、无推荐、审核关闭
				}
			}
			set_msg($_W,$_GPC['res_id']);
			echo json_encode(array('msg'=>'商城商品发布改变状态成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'商城商品发布改变状态出错','code'=>'500','res'=>$res),320);exit();
	}
  	//商店置顶
	public function doPageStoretoppay(){
		global $_GPC, $_W;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		$root=$_W['siteroot']; 
    	$primoney=pdo_get('zh_gjw_storemoney',array('uniacid'=>$_W['uniacid']));
		$total_fee =$primoney['topfee'];
		if($total_fee>0)
		{
			$body = "商城商品置顶";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
		echo json_encode($return);
	}
	//商店置顶topfee+1
	public function doPageStoretopsuccess(){
		global $_W, $_GPC;
		file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=GetGradestorep&m=zh_gjw&order_id=" . $_GPC['id']);//修改等级
		$topfee=pdo_get('zh_gjw_storepublish',array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		$topfee['topfee']=$topfee['topfee']+1;
		$res =	pdo_update('zh_gjw_storepublish', array('topfee' =>$topfee['topfee'],'uptime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if ($res) {
			if($_GPC['openid']&&$_GPC['top']==1){
				$datas['openid']=$_GPC['openid'];
				$datas['type']=14;
				$datas['uniacid']=$_W['uniacid'];
				$datas['number']=1;
				$datas['sjc']=time();
				$datas['time']=date('Y-m-d H:i:s',time());
				pdo_insert('zh_gjw_repucost',$datas);
			}else{
                $storemoney=pdo_get('zh_gjw_storemoney',array('uniacid'=>$_W['uniacid']));
                $data['p_id']=$_GPC['id'];
                $data['fee']=$storemoney['topfee'];
                $data['uniacid']=$_W['uniacid'];
                $data['time']=date('Y-m-d H:i:s',time());
                if ($storemoney['topfee']>0) {
                    pdo_insert('zh_gjw_storeorder',$data);
                }
            }
			echo json_encode(array('msg'=>'置顶成功','code'=>'200','res'=>$res),320);exit();
		}else{
			echo json_encode(array('msg'=>'置顶失败','code'=>'500'),320);exit();
		}
	}
	//商店推荐
	public function doPageStoreuppay(){
		global $_GPC, $_W;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		$root=$_W['siteroot']; 
    	$primoney=pdo_get('zh_gjw_storemoney',array('uniacid'=>$_W['uniacid']));
		$total_fee =$primoney['upfee'];
		if($total_fee>0)
		{
			$body = "商城商品推荐";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
		echo json_encode($return);
	}
	//商店推荐upfee+1
	public function doPageStoreupsuccess(){
		global $_W, $_GPC;
		file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=GetGradestorep&m=zh_gjw&order_id=" . $_GPC['id']);//修改等级
		$upfee=pdo_get('zh_gjw_storepublish',array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		$res =	pdo_update('zh_gjw_storepublish', array('upfee' =>1,'uptime'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if ($res) {
			if($_GPC['openid']&&$_GPC['up']==1){
				$datas['openid']=$_GPC['openid'];
				$datas['type']=13;
				$datas['uniacid']=$_W['uniacid'];
				$datas['number']=1;
				$datas['sjc']=time();
				$datas['time']=date('Y-m-d H:i:s',time());
				pdo_insert('zh_gjw_repucost',$datas);
			}else{
                $storemoney=pdo_get('zh_gjw_storemoney',array('uniacid'=>$_W['uniacid']));
                $data['p_id']=$_GPC['id'];
                $data['fee']=$storemoney['upfee'];
                $data['uniacid']=$_W['uniacid'];
                $data['time']=date('Y-m-d H:i:s',time());
                if ($storemoney['upfee']>0) {
                    pdo_insert('zh_gjw_storeorder',$data);
                }
            }
			echo json_encode(array('msg'=>'推荐成功','code'=>'200','res'=>$res),320);exit();
		}else{
			echo json_encode(array('msg'=>'推荐失败','code'=>'500'),320);exit();
		}
	}
	//商店浏览
	public function doPageStoreview(){
		global $_GPC, $_W;
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$id=pdo_get('zh_gjw_storepublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if (empty($id['view'])) {
			pdo_update('zh_gjw_storepublish', array('view' =>$user['id']), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
			echo json_encode(array('msg'=>'浏览成功','code'=>'200','res'=>1),320);exit();
		}else{
			$ids=explode(",",$id['view']);
			if (in_array($user['id'], $ids)){
				if (in_array(0,$ids)) {
					$idss=count($ids)-1;
				}else{
					$idss=count($ids);
				}
				echo json_encode(array('msg'=>'浏览过了','code'=>'201','res'=>$idss),320);exit();
			}else{
				array_push($ids,$user['id']);
				$view=implode(',', $ids);
				$res = pdo_update('zh_gjw_storepublish', array('view' =>$view), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
				if (empty($res)) {
					echo json_encode(array('msg'=>'浏览失败','code'=>'500'),320);exit();
				}
				$viewid=pdo_get('zh_gjw_storepublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
				if (in_array(0,explode(",",$viewid['view']))) {
					$viewids=count(explode(",",$viewid['view']))-1;
				}else{
					$viewids=count(explode(",",$viewid['view']));
				}
				echo json_encode(array('msg'=>'浏览成功','code'=>'200','res'=>$viewids),320);exit();
			}
		}
	}
	/**
	*商店点赞
	*/
	public function doPageStoreagree(){
		global $_GPC, $_W;
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$id=pdo_get('zh_gjw_storepublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		if (empty($id['agree'])) {
			pdo_update('zh_gjw_storepublish', array('agree' =>$user['id']), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
			echo json_encode(array('msg'=>'点赞成功','code'=>'200','res'=>1),320);exit();
		}else{
			$ids=explode(",",$id['agree']);
			if (in_array($user['id'], $ids)){
				if (in_array(0,$ids)) {
					$idss=count($ids)-1;
				}else{
					$idss=count($ids);
				}
				echo json_encode(array('msg'=>'点赞过了','code'=>'201','res'=>$idss),320);exit();
			}else{
				array_push($ids,$user['id']);
				$agree=implode(',', $ids);
				$res = pdo_update('zh_gjw_storepublish', array('agree' =>$agree), array('id' =>$_GPC['id'],'uniacid'=>$_W['uniacid']));
				if (empty($res)) {
					echo json_encode(array('msg'=>'点赞失败','code'=>'500'),320);exit();
				}
				$agreeid=pdo_get('zh_gjw_storepublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
				if (in_array(0,explode(",",$agreeid['agree']))) {
					$agreeids=count(explode(",",$agreeid['agree']))-1;
				}else{
					$agreeids=count(explode(",",$agreeid['agree']));
				}
				echo json_encode(array('msg'=>'点赞成功','code'=>'200','res'=>$agreeids),320);exit();
			}
		}
	}
	//商店详情点赞没有
	public function doPageStoreagreedetail(){
		global $_W, $_GPC;
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid'],'uniacid'=>$_W['uniacid']));
		$id=pdo_get('zh_gjw_storepublish',array('id'=>$_GPC['id'],'uniacid'=>$_W['uniacid']));
		// if (!empty($id)) {
			$ids=explode(",",$id['agree']);
			if (in_array($user['id'], $ids)){
					echo json_encode(array('msg'=>'点赞过了','code'=>'200'),320);exit();
			}else{
				echo json_encode(array('msg'=>'没有点赞过','code'=>'500'),320);exit();
			}
		// }
	}
  	//商店全部数据
	public function doPageStoreall(){
		global $_W, $_GPC;
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=6;
		$where=' WHERE  uniacid=:uniacid and state=:state ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':state']=2;
	    $sql="SELECT * FROM ".tablename('zh_gjw_storepublish') .$where." and nums>0 ORDER BY time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_storepublish').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		if (empty($res)) {
			echo json_encode(array('msg'=>'没有商城商品数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res) ; $i++) { 
				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$ures[$i]=pdo_get('zh_gjw_register',array('phone'=>$res[$i]['phone']));//?
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['ulevel_name']=$ures[$i]['level_name'];
				$res[$i]['username']=$ures[$i]['username'];
				$resu=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['reputation']=$resu['reputation'];
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['cusname']=$resu['cusname'];
				$res[$i]['level_name']=$resu['level_name'];
				$res[$i]['storeimg']=$resu['storeimg'];
			}
			if (empty($res)) {
				echo json_encode(array('msg'=>'商城商品数据','code'=>'500'),320);exit();
			}
			echo json_encode(array('msg'=>'商城商品数据','code'=>'200','res'=>$res),320);exit();
		}
	}
  	
	//商店数据推荐
	public function doPageStoreup(){
		global $_W, $_GPC;
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=6;
		$where=' WHERE  uniacid=:uniacid and state=:state and upfee=:upfee ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':state']=2;
	    $data[':upfee']=1;
	    $sql="SELECT * FROM ".tablename('zh_gjw_storepublish') .$where." and nums>0 ORDER BY uptime desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_storepublish').$where." ORDER BY uptime desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		if (empty($res)) {
			echo json_encode(array('msg'=>'没有商城商品推荐数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res) ; $i++) { 
				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$ures[$i]=pdo_get('zh_gjw_register',array('phone'=>$res[$i]['phone']));//?
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['ulevel_name']=$ures[$i]['level_name'];
				$res[$i]['username']=$ures[$i]['username'];
				$resu=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['reputation']=$resu['reputation'];
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['cusname']=$resu['cusname'];
				$res[$i]['level_name']=$resu['level_name'];
				$res[$i]['storeimg']=$resu['storeimg'];
			}
			if (empty($res)) {
				echo json_encode(array('msg'=>'商城商品推荐数据','code'=>'500'),320);exit();
			}
			echo json_encode(array('msg'=>'商城商品推荐数据','code'=>'200','res'=>$res),320);exit();
		}
	}
	//商店分类二级推荐数据
	public function doPageStoresubup(){
		global $_W, $_GPC;
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE  uniacid=:uniacid and state=:state and upfee=:upfee and ct_id=:ct_id ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':state']=2;
	    $data[':upfee']=1;
	    $data[':ct_id']=$_GPC['ct_id'];
	    $sql="SELECT * FROM ".tablename('zh_gjw_storepublish') .$where." and nums>0 ORDER BY uptime desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_storepublish').$where." ORDER BY uptime desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		if (empty($res)) {
			echo json_encode(array('msg'=>'没有商城商品分类数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res) ; $i++) { 
				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$ures[$i]=pdo_get('zh_gjw_register',array('phone'=>$res[$i]['phone']));//?
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['ulevel_name']=$ures[$i]['level_name'];
				$res[$i]['username']=$ures[$i]['username'];
				$resu=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['reputation']=$resu['reputation'];
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['cusname']=$resu['cusname'];
				$res[$i]['level_name']=$resu['level_name'];
				$res[$i]['storeimg']=$resu['storeimg'];
			}
			if (empty($res)) {
				echo json_encode(array('msg'=>'商城商品推荐数据','code'=>'500'),320);exit();
			}
			echo json_encode(array('msg'=>'商城商品推荐数据','code'=>'200','res'=>$res),320);exit();
		}
	}
	//商店分类数据
	public function doPageStorecuscateid(){
		global $_W, $_GPC;
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE  uniacid=:uniacid and state=:state and cth_id=:cth_id ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':state']=2;
	    $data[':cth_id']=$_GPC['cth_id'];
	    $sql="SELECT * FROM ".tablename('zh_gjw_storepublish') .$where." and nums>0 ORDER BY time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_storepublish').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		if (empty($res)) {
			echo json_encode(array('msg'=>'没有商城商品分类数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res) ; $i++) { 
				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$ures[$i]=pdo_get('zh_gjw_register',array('phone'=>$res[$i]['phone']));//?
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['ulevel_name']=$ures[$i]['level_name'];
				$res[$i]['username']=$ures[$i]['username'];
				$resu=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone']));
    			$totalmoney=pdo_get('zh_gjw_reputationrecord', array('openid' => $resu['openid'], 'uniacid' => $_W['uniacid'],'pay'=>2), array('sum(money) as total_money'));
				$res[$i]['reputation']=$resu['reputation'];
				$res[$i]['xybzj']=$totalmoney['total_money'];
				$res[$i]['cusname']=$resu['cusname'];
				$res[$i]['level_name']=$resu['level_name'];
				$res[$i]['storeimg']=$resu['storeimg'];
			}
			if (empty($res)) {
				echo json_encode(array('msg'=>'商城商品分类数据','code'=>'500'),320);exit();
			}
			echo json_encode(array('msg'=>'商城商品分类数据','code'=>'200','res'=>$res),320);exit();
		}
	}
  	
	//商店分类二级数据
	public function doPageStoresub(){
		global $_W, $_GPC;
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=8;
		$where=' WHERE  uniacid=:uniacid and state=:state and ct_id=:ct_id ';
	    $data[':uniacid']=$_W['uniacid'];
	    $data[':state']=2;
	    $data[':ct_id']=$_GPC['ct_id'];
	    $sql="SELECT * FROM ".tablename('zh_gjw_storepublish') .$where." and nums>0 ORDER BY time desc";
    	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_storepublish').$where." ORDER BY time desc",$data);
    	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);
		if (empty($res)) {
			echo json_encode(array('msg'=>'没有商城商品分类数据','code'=>'500'),320);exit();
		}else{
			for ($i=0; $i <count($res) ; $i++) { 
				$agreeids=explode(",",$res[$i]['agree']);
				if (in_array(0, $agreeids)){
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']))-1;
				}else{
					$res[$i]['agree']=count(explode(",",$res[$i]['agree']));
				}
				$viewids=explode(",",$res[$i]['view']);
				if (in_array(0, $viewids)){
					$res[$i]['view']=count(explode(",",$res[$i]['view']))-1;
				}else{
					$res[$i]['view']=count(explode(",",$res[$i]['view']));
				}
				$ures[$i]=pdo_get('zh_gjw_register',array('phone'=>$res[$i]['phone']));//?
				$res[$i]['avatar']=$ures[$i]['avatar'];
				$res[$i]['ulevel_name']=$ures[$i]['level_name'];
				$res[$i]['username']=$ures[$i]['username'];
				$resu=pdo_get('zh_gjw_cusmanage',array('phone'=>$res[$i]['phone']));
				$res[$i]['cusname']=$resu['cusname'];
				$res[$i]['level_name']=$resu['level_name'];
				$res[$i]['storeimg']=$resu['storeimg'];
			}
			if (empty($res)) {
				echo json_encode(array('msg'=>'商城商品二级数据','code'=>'500'),320);exit();
			}
			echo json_encode(array('msg'=>'商城商品二级数据','code'=>'200','res'=>$res),320);exit();
		}
	}
  	
	//生成商店订单
	public function doPageStoreorder(){
		global $_W,$_GPC;
		$cus_id=pdo_get('zh_gjw_storepublish',array('id'=>$_GPC['p_id']));
		$cusm=pdo_get('zh_gjw_cusmanage',array('phone'=>$cus_id['phone']));
		$u_id=pdo_get('zh_gjw_register',array('uniacid'=>$_W['uniacid'],'openid'=>$_GPC['openid']));
		$data['u_id']=$u_id['id'];
		$data['formid']=$_GPC['formid'];
		$data['cus_id']=$cusm['id'];
		$data['p_id']=$_GPC['p_id'];
		$data['type']=$_GPC['type'];
		$data['ordernum']=date('Ymdhis').$u_id['id'].rand(10,99);
		$data['ofee']=$_GPC['ofee'];
		$data['message']=$_GPC['message'];
		$data['phone']=$_GPC['phone'];
		$data['uname']=$_GPC['name'];
		$data['state']=1;
		$data['address']=$_GPC['address'];
		$data['num']=$_GPC['num'];
		$data['ofees']=$_GPC['ofees'];
		$data['uniacid']=$_W['uniacid'];
		$data['time']=date('Y-m-d H:i:s',time());
		$data['timesjc']=time();
		$res=pdo_insert('zh_gjw_orders',$data);
		$res_id=pdo_insertid();
		if (empty($res)) {
			echo json_encode(array('msg'=>'提交失败','code'=>'500'),320);exit();
		}
		echo json_encode(array('msg'=>'提交成功','code'=>'200','res_id'=>$res_id),320);exit();

	}
	//商店订单支付
	public function doPageStoreorderpay(){
		global $_W,$_GPC;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		pdo_update('zh_gjw_orders', array('paycode' =>$out_trade_no), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		$root=$_W['siteroot']; 
		$total_fee =$_GPC['ofees'];
		if($total_fee>0)
		{
			$body = "商城商品订单支付";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
		echo json_encode($return);
	}

	//商店订单支付成功改变state
	public function doPageStoreorderpaysuccess(){
		global $_W, $_GPC;
		/*function getaccess_token($_W){
          $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
          $appid=$res['appid'];
          $secret=$res['appsecret'];
          $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL,$url);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
          $data = curl_exec($ch);
          curl_close($ch);
          $data = json_decode($data,true);
          return $data['access_token'];
        }*/
        function set_msg($_W,$res){
            //$access_token = getaccess_token($_W);
            $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
            $user=pdo_get('zh_gjw_register',array('id'=>$res['u_id']));
            $orders=pdo_get('zh_gjw_orders',array('id'=>$res['id']));
            $storename=pdo_get('zh_gjw_storepublish',array('id'=>$res['p_id']));
            $formwork ='{
                "touser": "'.$user["openid"].'",
                "template_id": "'.$ress["templeidos"].'",
                "form_id":"'.$orders['formid'].'",
                "data": {
                    "keyword1": {
                        "value": "'.$orders['time'].'",
                        "color": "#173177"
                    },
                    "keyword2": {
                        "value":"'.$orders['paytime'].'",
                        "color": "#173177"
                    },
                    "keyword3": {
                        "value":"'.$storename['title'].'",
                        "color": "#173177"
                    },
                    "keyword4": {
                        "value":"'.$orders['ordernum'].'",
                        "color": "#173177"
                    },
                    "keyword5": {
                        "value":"'.$orders['ofees'].'",
                        "color": "#173177"
                    },
                    "keyword6": {
                        "value":"'.$orders['id'].'",
                        "color": "#173177"
                    },
                    "keyword7": {
                        "value":"商城商品购买成功",
                        "color": "#173177"
                    }
                }  
            }';
            $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL,$url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
            curl_setopt($ch, CURLOPT_POST,1);
            curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
            $data = curl_exec($ch);
            curl_close($ch);
           return $data;
        }
		$res = pdo_update('zh_gjw_orders', array('state' =>2,'paytime' =>date('Y-m-d H:i:s')), array('id' =>$_GPC['res_id'],'uniacid'=>$_W['uniacid']));
		if ($res) {
			$nums=pdo_get('zh_gjw_orders',array('id'=>$_GPC['res_id']));
			$num=pdo_get('zh_gjw_storepublish',array('id'=>$nums['p_id']));
			$numbers=$num['nums']-$nums['num'];
			pdo_update('zh_gjw_storepublish', array('nums' =>$numbers), array('id' =>$num['id']));
          
                file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=GetGrade&m=zh_gjw&order_id=" . $_GPC['res_id']);//修改等级
			set_msg($_W,$res);
			echo json_encode(array('msg'=>'成功','code'=>'200'),320);exit();
		}
		echo json_encode(array('msg'=>'失败','code'=>'500'),320);exit();
	}
  	
    public function doPageGetGrade()
    {
        global $_W, $_GPC;
        function getLevel($members, $xf_money)
        {
            for ($i = 0; $i < count($members); $i++) {
                if ($xf_money >= $members[$i]['money']) {
                    return $members[$i]['name'];
                }
                if ($xf_money < $members[$i]['money'] && $xf_money > $members[$i + 1]['money']) {
                    return $members[$i + 1]['name'];
                }
            }
        }
        $order_id = $_GPC['order_id'];
        $orderInfo = pdo_get('zh_gjw_orders', array('id' => $order_id));
        $userordermoney = pdo_get('zh_gjw_orders', array('u_id' => $orderInfo['u_id'], 'uniacid' => $_W['uniacid']), array('sum(ofees) as total_money'));
        $storemoney = pdo_get('zh_gjw_orders', array('cus_id' => $orderInfo['cus_id'], 'uniacid' => $_W['uniacid']), array('sum(ofees) as total_money'));
        $cusid = pdo_get('zh_gjw_cusmanage', array('id' => $orderInfo['cus_id']));
        $userid = pdo_get('zh_gjw_register', array('openid' => $cusid['openid']));
        $cdbmoney = pdo_get('zh_gjw_dbpublish', array('phone' => $cusid['phone'],'uniacid' => $_W['uniacid'],'pay' =>1), array('sum(payfee) as total_money'));
        $cdbupmoney = pdo_get('zh_gjw_dborder', array('p_id' => $cdbmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $cshotmoney = pdo_get('zh_gjw_shotpublish', array('phone' => $cusid['phone'],'uniacid' => $_W['uniacid'],'pay' =>1), array('sum(payfee) as total_money'));
        $cshotupmoney = pdo_get('zh_gjw_shotorder', array('p_id' => $cshotmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $cmarketmoney = pdo_get('zh_gjw_marketpublish', array('phone' => $cusid['phone'],'uniacid' => $_W['uniacid'],'pay' =>1), array('sum(payfee) as total_money'));
        $cmarketupmoney = pdo_get('zh_gjw_marketorder', array('p_id' => $cmarketmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $cstoremoney = pdo_get('zh_gjw_storepublish', array('phone' => $cusid['phone'],'uniacid' => $_W['uniacid'],'pay' =>1), array('sum(payfee) as total_money'));
        $cstoreupmoney = pdo_get('zh_gjw_storeorder', array('p_id' => $cstoremoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $cprimoney = pdo_get('zh_gjw_pripublish', array('phone' => $cusid['phone'],'uniacid' => $_W['uniacid'],'pay' =>1), array('sum(payfee) as total_money'));
        $cpriupmoney = pdo_get('zh_gjw_priorder', array('p_id' => $cprimoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $cprilookmoney = pdo_get('zh_gjw_prilookorder', array('u_id' => $userid['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $cusmoney=$userordermoney['total_money']+$cdbmoney['total_money']+$cshotmoney['total_money']+$cmarketmoney['total_money']+$cstoremoney['total_money']+$cprimoney['total_money']+$cdbupmoney['total_money']+$cshotupmoney['total_money']+$cmarketupmoney['total_money']+$cstoreupmoney['total_money']+$cpriupmoney['total_money']+$cprilookmoney['total_money']+$cusid['payfee'];

        $uuserid = pdo_get('zh_gjw_register', array('id' => $userordermoney['u_id']));
        $uupdb = pdo_get('zh_gjw_dbpublish', array('phone' => $uuserid['phone']));
        $uuppri = pdo_get('zh_gjw_pripublish', array('phone' => $uuserid['phone']));
        $udbupmoney = pdo_get('zh_gjw_dborder', array('p_id' => $uupdb['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $upriupmoney = pdo_get('zh_gjw_priorder', array('p_id' => $uuppri['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $usermoney=$userordermoney['total_money']+$udbupmoney['total_money']+$upriupmoney['total_money'];
        $store = pdo_getall('zh_gjw_storegrade', array('uniacid' => $_W['uniacid']), array(), '', 'money DESC');
        $user = pdo_getall('zh_gjw_usergrade', array('uniacid' => $_W['uniacid']), array(), '', 'money DESC');
        $username = getLevel($user, $usermoney);
        $storename = getLevel($store, $cusmoney);
        if ($username) {
            pdo_update('zh_gjw_register', array('level_name' => $username), array('id' => $orderInfo['u_id']));
        }
        /*if ($storename) {
            pdo_update('zh_gjw_cusmanage', array('level_name' => $storename), array('id' => $orderInfo['cus_id']));
        }*/

    }
    public function doPageGetGradedbp()
    {
        global $_W, $_GPC;
        function getLevel($members, $xf_money)
        {
            for ($i = 0; $i < count($members); $i++) {
                if ($xf_money >= $members[$i]['money']) {
                    return $members[$i]['name'];
                }
                if ($xf_money < $members[$i]['money'] && $xf_money > $members[$i + 1]['money']) {
                    return $members[$i + 1]['name'];
                }
            }
        }
        $order_id = $_GPC['order_id'];
        $dbInfo = pdo_get('zh_gjw_dbpublish', array('id' => $order_id));
        $userid = pdo_get('zh_gjw_register', array('phone' => $dbInfo['phone']));
        $cusid = pdo_get('zh_gjw_cusmanage', array('phone' => $userid['phone']));
        $ordermoney = pdo_get('zh_gjw_orders', array('u_id' => $userid['id'], 'uniacid' => $_W['uniacid']), array('sum(ofees) as total_money'));
        $dbpmoney = pdo_get('zh_gjw_dbpublish', array('phone' => $dbInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $dbupmoney = pdo_get('zh_gjw_dborder', array('p_id' => $dbpmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $shotpmoney = pdo_get('zh_gjw_shotpublish', array('phone' => $dbInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $shotupmoney = pdo_get('zh_gjw_shotorder', array('p_id' => $shotpmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $marketpmoney = pdo_get('zh_gjw_marketpublish', array('phone' => $dbInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $marketupmoney = pdo_get('zh_gjw_marketorder', array('p_id' => $marketpmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $storepmoney = pdo_get('zh_gjw_storepublish', array('phone' => $dbInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $storeupmoney = pdo_get('zh_gjw_storeorder', array('p_id' => $storepmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $pripmoney = pdo_get('zh_gjw_pripublish', array('phone' => $dbInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $priupmoney = pdo_get('zh_gjw_priorder', array('p_id' => $pripmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $prilookmoney = pdo_get('zh_gjw_prilookorder', array('u_id' => $userid['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $cusmoney=$ordermoney['total_money']+$dbpmoney['total_money']+$dbupmoney['total_money']+$shotpmoney['total_money']+$shotupmoney['total_money']+$marketpmoney['total_money']+$marketupmoney['total_money']+$storepmoney['total_money']+$storeupmoney['total_money']+$pripmoney['total_money']+$priupmoney['total_money']+$prilookmoney['total_money']+$cusid['payfee'];
        $usermoney=$ordermoney['total_money']+$dbupmoney['total_money']+$priupmoney['total_money'];
        $store = pdo_getall('zh_gjw_storegrade', array('uniacid' => $_W['uniacid']), array(), '', 'money DESC');
        $user = pdo_getall('zh_gjw_usergrade', array('uniacid' => $_W['uniacid']), array(), '', 'money DESC');
        $username = getLevel($user, $usermoney);
        $storename = getLevel($store, $cusmoney);
        /*if ($cusid) {
        	if ($storename) {
            	pdo_update('zh_gjw_cusmanage', array('level_name' => $storename), array('id' => $cusid['id']));
	        }
        }*/
        if ($username) {
            pdo_update('zh_gjw_register', array('level_name' => $username), array('phone' => $dbInfo['phone']));
        }

    }

    public function doPageGetGradeprip()
    {
        global $_W, $_GPC;
        function getLevel($members, $xf_money)
        {
            for ($i = 0; $i < count($members); $i++) {
                if ($xf_money >= $members[$i]['money']) {
                    return $members[$i]['name'];
                }
                if ($xf_money < $members[$i]['money'] && $xf_money > $members[$i + 1]['money']) {
                    return $members[$i + 1]['name'];
                }
            }
        }
        $order_id = $_GPC['order_id'];
        $priInfo = pdo_get('zh_gjw_pripublish', array('id' => $order_id));

        $userid = pdo_get('zh_gjw_register', array('phone' => $priInfo['phone']));
        $cusid = pdo_get('zh_gjw_cusmanage', array('phone' => $userid['phone']));
        $ordermoney = pdo_get('zh_gjw_orders', array('u_id' => $userid['id'], 'uniacid' => $_W['uniacid']), array('sum(ofees) as total_money'));
        $dbpmoney = pdo_get('zh_gjw_dbpublish', array('phone' => $priInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $dbupmoney = pdo_get('zh_gjw_dborder', array('p_id' => $dbpmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $shotpmoney = pdo_get('zh_gjw_shotpublish', array('phone' => $priInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $shotupmoney = pdo_get('zh_gjw_shotorder', array('p_id' => $shotpmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $marketpmoney = pdo_get('zh_gjw_marketpublish', array('phone' => $priInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $marketupmoney = pdo_get('zh_gjw_marketorder', array('p_id' => $marketpmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $storepmoney = pdo_get('zh_gjw_storepublish', array('phone' => $priInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $storeupmoney = pdo_get('zh_gjw_storeorder', array('p_id' => $storepmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $pripmoney = pdo_get('zh_gjw_pripublish', array('phone' => $priInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $priupmoney = pdo_get('zh_gjw_priorder', array('p_id' => $pripmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $prilookmoney = pdo_get('zh_gjw_prilookorder', array('u_id' => $userid['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $cusmoney=$ordermoney['total_money']+$dbpmoney['total_money']+$dbupmoney['total_money']+$shotpmoney['total_money']+$shotupmoney['total_money']+$marketpmoney['total_money']+$marketupmoney['total_money']+$storepmoney['total_money']+$storeupmoney['total_money']+$pripmoney['total_money']+$priupmoney['total_money']+$prilookmoney['total_money']+$cusid['payfee'];
        $usermoney=$ordermoney['total_money']+$dbupmoney['total_money']+$priupmoney['total_money'];

        $store = pdo_getall('zh_gjw_storegrade', array('uniacid' => $_W['uniacid']), array(), '', 'money DESC');
        $user = pdo_getall('zh_gjw_usergrade', array('uniacid' => $_W['uniacid']), array(), '', 'money DESC');
        $username = getLevel($user, $usermoney);
        $storename = getLevel($store, $cusmoney);
        /*if ($cusid) {
        	if ($storename) {
            	pdo_update('zh_gjw_cusmanage', array('level_name' => $storename), array('id' => $cusid['id']));
	        }
        }*/
        if ($username) {
            pdo_update('zh_gjw_register', array('level_name' => $username), array('phone' => $priInfo['phone']));
        }

    }

    public function doPageGetGradeshotp()
    {
        global $_W, $_GPC;
        function getLevel($members, $xf_money)
        {
            for ($i = 0; $i < count($members); $i++) {
                if ($xf_money >= $members[$i]['money']) {
                    return $members[$i]['name'];
                }
                if ($xf_money < $members[$i]['money'] && $xf_money > $members[$i + 1]['money']) {
                    return $members[$i + 1]['name'];
                }
            }
        }
        $order_id = $_GPC['order_id'];
        $shotInfo = pdo_get('zh_gjw_shotpublish', array('id' => $order_id));

        $userid = pdo_get('zh_gjw_register', array('phone' => $shotInfo['phone']));
        $cusid = pdo_get('zh_gjw_cusmanage', array('phone' => $userid['phone']));
        $ordermoney = pdo_get('zh_gjw_orders', array('u_id' => $userid['id'], 'uniacid' => $_W['uniacid']), array('sum(ofees) as total_money'));
        $dbpmoney = pdo_get('zh_gjw_dbpublish', array('phone' => $shotInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $dbupmoney = pdo_get('zh_gjw_dborder', array('p_id' => $dbpmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $shotpmoney = pdo_get('zh_gjw_shotpublish', array('phone' => $shotInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $shotupmoney = pdo_get('zh_gjw_shotorder', array('p_id' => $shotpmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $marketpmoney = pdo_get('zh_gjw_marketpublish', array('phone' => $shotInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $marketupmoney = pdo_get('zh_gjw_marketorder', array('p_id' => $marketpmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $storepmoney = pdo_get('zh_gjw_storepublish', array('phone' => $shotInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $storeupmoney = pdo_get('zh_gjw_storeorder', array('p_id' => $storepmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $pripmoney = pdo_get('zh_gjw_pripublish', array('phone' => $shotInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $priupmoney = pdo_get('zh_gjw_priorder', array('p_id' => $pripmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $prilookmoney = pdo_get('zh_gjw_prilookorder', array('u_id' => $userid['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $cusmoney=$ordermoney['total_money']+$dbpmoney['total_money']+$dbupmoney['total_money']+$shotpmoney['total_money']+$shotupmoney['total_money']+$marketpmoney['total_money']+$marketupmoney['total_money']+$storepmoney['total_money']+$storeupmoney['total_money']+$pripmoney['total_money']+$priupmoney['total_money']+$prilookmoney['total_money']+$cusid['payfee'];
        $usermoney=$ordermoney['total_money']+$dbupmoney['total_money']+$priupmoney['total_money'];

        $store = pdo_getall('zh_gjw_storegrade', array('uniacid' => $_W['uniacid']), array(), '', 'money DESC');
        $user = pdo_getall('zh_gjw_usergrade', array('uniacid' => $_W['uniacid']), array(), '', 'money DESC');
        $username = getLevel($user, $usermoney);
        $storename = getLevel($store, $cusmoney);
        /*if ($cusid) {
        	if ($storename) {
            	pdo_update('zh_gjw_cusmanage', array('level_name' => $storename), array('id' => $cusid['id']));
	        }
        }*/
        if ($username) {
            pdo_update('zh_gjw_register', array('level_name' => $username), array('phone' => $shotInfo['phone']));
        }

    }
    public function doPageGetGrademarketp()
    {
        global $_W, $_GPC;
        function getLevel($members, $xf_money)
        {
            for ($i = 0; $i < count($members); $i++) {
                if ($xf_money >= $members[$i]['money']) {
                    return $members[$i]['name'];
                }
                if ($xf_money < $members[$i]['money'] && $xf_money > $members[$i + 1]['money']) {
                    return $members[$i + 1]['name'];
                }
            }
        }
        $order_id = $_GPC['order_id'];
        $marketInfo = pdo_get('zh_gjw_marketpublish', array('id' => $order_id));

        $userid = pdo_get('zh_gjw_register', array('phone' => $marketInfo['phone']));
        $cusid = pdo_get('zh_gjw_cusmanage', array('phone' => $userid['phone']));
        $ordermoney = pdo_get('zh_gjw_orders', array('u_id' => $userid['id'], 'uniacid' => $_W['uniacid']), array('sum(ofees) as total_money'));
        $dbpmoney = pdo_get('zh_gjw_dbpublish', array('phone' => $marketInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $dbupmoney = pdo_get('zh_gjw_dborder', array('p_id' => $dbpmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $shotpmoney = pdo_get('zh_gjw_shotpublish', array('phone' => $marketInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $shotupmoney = pdo_get('zh_gjw_shotorder', array('p_id' => $shotpmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $marketpmoney = pdo_get('zh_gjw_marketpublish', array('phone' => $marketInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $marketupmoney = pdo_get('zh_gjw_marketorder', array('p_id' => $marketpmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $storepmoney = pdo_get('zh_gjw_storepublish', array('phone' => $marketInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $storeupmoney = pdo_get('zh_gjw_storeorder', array('p_id' => $storepmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $pripmoney = pdo_get('zh_gjw_pripublish', array('phone' => $marketInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $priupmoney = pdo_get('zh_gjw_priorder', array('p_id' => $pripmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $prilookmoney = pdo_get('zh_gjw_prilookorder', array('u_id' => $userid['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $cusmoney=$ordermoney['total_money']+$dbpmoney['total_money']+$dbupmoney['total_money']+$shotpmoney['total_money']+$shotupmoney['total_money']+$marketpmoney['total_money']+$marketupmoney['total_money']+$storepmoney['total_money']+$storeupmoney['total_money']+$pripmoney['total_money']+$priupmoney['total_money']+$prilookmoney['total_money']+$cusid['payfee'];
        $usermoney=$ordermoney['total_money']+$dbupmoney['total_money']+$priupmoney['total_money'];

        $store = pdo_getall('zh_gjw_storegrade', array('uniacid' => $_W['uniacid']), array(), '', 'money DESC');
        $user = pdo_getall('zh_gjw_usergrade', array('uniacid' => $_W['uniacid']), array(), '', 'money DESC');
        $username = getLevel($user, $usermoney);
        $storename = getLevel($store, $cusmoney);
        /*if ($cusid) {
        	if ($storename) {
            	pdo_update('zh_gjw_cusmanage', array('level_name' => $storename), array('id' => $cusid['id']));
	        }
        }*/
        if ($username) {
            pdo_update('zh_gjw_register', array('level_name' => $username), array('phone' => $marketInfo['phone']));
        }

    }
    public function doPageGetGradestorep()
    {
        global $_W, $_GPC;
        function getLevel($members, $xf_money)
        {
            for ($i = 0; $i < count($members); $i++) {
                if ($xf_money >= $members[$i]['money']) {
                    return $members[$i]['name'];
                }
                if ($xf_money < $members[$i]['money'] && $xf_money > $members[$i + 1]['money']) {
                    return $members[$i + 1]['name'];
                }
            }
        }
        $order_id = $_GPC['order_id'];
        $storeInfo = pdo_get('zh_gjw_storepublish', array('id' => $order_id));
        
        $userid = pdo_get('zh_gjw_register', array('phone' => $storeInfo['phone']));
        $cusid = pdo_get('zh_gjw_cusmanage', array('phone' => $userid['phone']));
        $ordermoney = pdo_get('zh_gjw_orders', array('u_id' => $userid['id'], 'uniacid' => $_W['uniacid']), array('sum(ofees) as total_money'));
        $dbpmoney = pdo_get('zh_gjw_dbpublish', array('phone' => $storeInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $dbupmoney = pdo_get('zh_gjw_dborder', array('p_id' => $dbpmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $shotpmoney = pdo_get('zh_gjw_shotpublish', array('phone' => $storeInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $shotupmoney = pdo_get('zh_gjw_shotorder', array('p_id' => $shotpmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $marketpmoney = pdo_get('zh_gjw_marketpublish', array('phone' => $storeInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $marketupmoney = pdo_get('zh_gjw_marketorder', array('p_id' => $marketpmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $storepmoney = pdo_get('zh_gjw_storepublish', array('phone' => $storeInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $storeupmoney = pdo_get('zh_gjw_storeorder', array('p_id' => $storepmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $pripmoney = pdo_get('zh_gjw_pripublish', array('phone' => $storeInfo['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $priupmoney = pdo_get('zh_gjw_priorder', array('p_id' => $pripmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $prilookmoney = pdo_get('zh_gjw_prilookorder', array('u_id' => $userid['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $cusmoney=$ordermoney['total_money']+$dbpmoney['total_money']+$dbupmoney['total_money']+$shotpmoney['total_money']+$shotupmoney['total_money']+$marketpmoney['total_money']+$marketupmoney['total_money']+$storepmoney['total_money']+$storeupmoney['total_money']+$pripmoney['total_money']+$priupmoney['total_money']+$prilookmoney['total_money']+$cusid['payfee'];
        $usermoney=$ordermoney['total_money']+$dbupmoney['total_money']+$priupmoney['total_money'];

        $store = pdo_getall('zh_gjw_storegrade', array('uniacid' => $_W['uniacid']), array(), '', 'money DESC');
        $user = pdo_getall('zh_gjw_usergrade', array('uniacid' => $_W['uniacid']), array(), '', 'money DESC');
        $username = getLevel($user, $usermoney);
        $storename = getLevel($store, $cusmoney);
        /*if ($cusid) {
        	if ($storename) {
            	pdo_update('zh_gjw_cusmanage', array('level_name' => $storename), array('id' => $cusid['id']));
	        }
        }*/
        if ($username) {
            pdo_update('zh_gjw_register', array('level_name' => $username), array('phone' => $storeInfo['phone']));
        }

    }
  	public function doPageGetGradelook()
    {
        global $_W, $_GPC;
        function getLevel($members, $xf_money)
        {
            for ($i = 0; $i < count($members); $i++) {
                if ($xf_money >= $members[$i]['money']) {
                    return $members[$i]['name'];
                }
                if ($xf_money < $members[$i]['money'] && $xf_money > $members[$i + 1]['money']) {
                    return $members[$i + 1]['name'];
                }
            }
        }
        $order_id = $_GPC['order_id'];
        $cusid = pdo_get('zh_gjw_cusmanage', array('openid' => $order_id));
        $userid = pdo_get('zh_gjw_register', array('openid' => $order_id));

        $ordermoney = pdo_get('zh_gjw_orders', array('u_id' => $userid['id'], 'uniacid' => $_W['uniacid']), array('sum(ofees) as total_money'));
        $dbpmoney = pdo_get('zh_gjw_dbpublish', array('phone' => $userid['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $dbupmoney = pdo_get('zh_gjw_dborder', array('p_id' => $dbpmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $shotpmoney = pdo_get('zh_gjw_shotpublish', array('phone' => $userid['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $shotupmoney = pdo_get('zh_gjw_shotorder', array('p_id' => $shotpmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $marketpmoney = pdo_get('zh_gjw_marketpublish', array('phone' => $userid['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $marketupmoney = pdo_get('zh_gjw_marketorder', array('p_id' => $marketpmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $storepmoney = pdo_get('zh_gjw_storepublish', array('phone' => $userid['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $storeupmoney = pdo_get('zh_gjw_storeorder', array('p_id' => $storepmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $pripmoney = pdo_get('zh_gjw_pripublish', array('phone' => $userid['phone'], 'uniacid' => $_W['uniacid']), array('sum(payfee) as total_money'));
        $priupmoney = pdo_get('zh_gjw_priorder', array('p_id' => $pripmoney['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $prilookmoney = pdo_get('zh_gjw_prilookorder', array('u_id' => $userid['id'], 'uniacid' => $_W['uniacid']), array('sum(fee) as total_money'));
        $cusmoney=$ordermoney['total_money']+$dbpmoney['total_money']+$dbupmoney['total_money']+$shotpmoney['total_money']+$shotupmoney['total_money']+$marketpmoney['total_money']+$marketupmoney['total_money']+$storepmoney['total_money']+$storeupmoney['total_money']+$pripmoney['total_money']+$priupmoney['total_money']+$prilookmoney['total_money']+$cusid['payfee'];

        $store = pdo_getall('zh_gjw_storegrade', array('uniacid' => $_W['uniacid']), array(), '', 'money DESC');
        $storename = getLevel($store, $cusmoney);
        if ($cusid) {
        	if ($storename) {
            	pdo_update('zh_gjw_cusmanage', array('level_name' => $storename), array('id' => $cusid['id']));
	        }
        }

    }
  	
    /**
	*获取商城评论
	*/
	public function doPageStoreassessget(){
		global $_GPC, $_W;
		$pageindex = max(1, intval($_GPC['page']));
		$pagesize=10;
		$where=' WHERE a.uniacid=:uniacid and d.id=:store_id and a.state=:state and b.type=:type ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':store_id']=$_GPC['store_id'];
		$data[':state']=2;
		$data[':type']=4;
		$sql="SELECT a.*,c.avatar,c.username,d.id as store_id FROM ".tablename('zh_gjw_orderassess'). " a left join " . tablename("zh_gjw_orders") . " b on b.id=a.p_id left join " . tablename("zh_gjw_register") . "c on c.id=b.u_id left join " . tablename("zh_gjw_storepublish") . " d on d.id=b.p_id " .$where." ORDER BY a.time desc";
  		$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_orderassess'). " a left join " . tablename("zh_gjw_orders") . " b on b.id=a.p_id left join " . tablename("zh_gjw_register") . "c on c.id=b.u_id left join " . tablename("zh_gjw_storepublish") . " d on d.id=b.p_id " .$where." ORDER BY a.time desc",$data);
  		$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
		$res=pdo_fetchall($select_sql,$data);

		if (empty($res)) {
			echo json_encode(array('msg'=>'获取失败','code'=>'500'),320);exit();
		}
      	
		for ($i=0; $i <count($res) ; $i++) { 
			if($res[$i]['img']){
            	$res[$i]['img']=explode(',', $res[$i]['img']);
            }
		}
		echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res),320);exit();
	}
  	
    //获取信誉保证金
    public function doPageReputation(){
		global $_GPC, $_W;
		$res=pdo_getall('zh_gjw_reputation',array('uniacid'=>$_W['uniacid']), array() , '' , 'sort DESC' , array());
		if ($res) {
			echo json_encode(array('msg'=>'成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'失败','code'=>'500'),320);exit();

	}
  	//信誉保证金支付
	public function doPageReputationpay(){
		global $_W, $_GPC;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$cusname=pdo_get('zh_gjw_cusmanage',array('phone'=>$_GPC['admin'],'uniacid'=>$_W['uniacid']));
		$gradenum=pdo_get('zh_gjw_reputation',array('grade'=>$_GPC['grade'],'uniacid'=>$_W['uniacid']));
		$appid=$res['appid'];
		$openid=$cusname['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();

		$data['pay']=1;
		$data['grade']=$_GPC['grade'];
		$data['money']=$_GPC['money'];
		$data['openid']=$openid;
		$data['paycode']=$out_trade_no;
		$data['uniacid']=$_W['uniacid'];
		$data['time']=date('Y-m-d H:i:s',time());
		$data['timesjc']=time();
		$data['pubdbnum']=$gradenum['pubdbnum'];
		$data['pubwpnum']=$gradenum['pubwpnum'];
		$data['pubjsnum']=$gradenum['pubjsnum'];
		$data['pubscnum']=$gradenum['pubscnum'];
		$data['pubcunum']=$gradenum['pubcunum'];
		$data['pubusnum']=$gradenum['pubusnum'];
		$data['upnum']=$gradenum['upnum'];
		$data['topnum']=$gradenum['topnum'];
		pdo_insert('zh_gjw_reputationrecord',$data);
		$res_id=pdo_insertid();

		$root=$_W['siteroot']; 
		$total_fee =$_GPC['money'];
		if($total_fee>0)
		{
			$body = "信用保证金";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
		//echo json_encode($return);
		echo json_encode(array('msg'=>'参数','code'=>'200','res_id'=>$res_id,'return'=>$return),320);exit();
	}
  	//信誉保证金支付成功改变state
	public function doPageReputationpaysuccess(){
		global $_W, $_GPC;
	    function getLevels($members, $xf_money)
        {
            for ($i = 0; $i < count($members); $i++) {
                if ($xf_money >= $members[$i]['money']) {
                    return $members[$i]['grade'];
                }
                if ($xf_money < $members[$i]['money'] && $xf_money > $members[$i + 1]['money']) {
                    return $members[$i + 1]['grade'];
                }
            }
        }
		$openid=pdo_get('zh_gjw_reputationrecord',array('id'=>$_GPC['id']));
	    $res=pdo_update('zh_gjw_reputationrecord',array('pay'=>2),array('id'=>$_GPC['id']));
	    if ($res) {
			$allmoney = pdo_get('zh_gjw_reputationrecord', array('pay' => 2,'openid' => $openid['openid'], 'uniacid' => $_W['uniacid']), array('sum(money) as total_money'));
			$store = pdo_getall('zh_gjw_reputation', array('uniacid' => $_W['uniacid']), array(), '', 'money DESC');
	        $storename = getLevels($store, $allmoney['total_money']);
	    	pdo_update('zh_gjw_cusmanage',array('reputation'=>$storename),array('openid'=>$openid['openid']));

	    	echo json_encode(array('msg'=>'成功','code'=>'200'),320);exit();
		}
		echo json_encode(array('msg'=>'失败','code'=>'500'),320);exit();
	}
  	//获取信誉保证金记录
    public function doPageReputationrecord(){
		global $_GPC, $_W;
		$cusname=pdo_get('zh_gjw_cusmanage',array('phone'=>$_GPC['admin']));
		$res=pdo_getall('zh_gjw_reputationrecord',array('uniacid'=>$_W['uniacid'],'openid'=>$cusname['openid'],'pay'=>2), array() , '' , 'timesjc DESC' , array());
		if ($res) {
			echo json_encode(array('msg'=>'成功','code'=>'200','res'=>$res),320);exit();
		}
		echo json_encode(array('msg'=>'失败','code'=>'500'),320);exit();

	}
  	
	//商家信誉保证金一年后提现
	public function doPageReputationtx(){
		global $_GPC, $_W;
      	function getGrade($members, $xf_money)
        {
            for ($i = 0; $i < count($members); $i++) {
                if ($xf_money >= $members[$i]['money']) {
                    return $members[$i]['grade'];
                }
                if ($xf_money < $members[$i]['money'] && $xf_money > $members[$i + 1]['money']) {
                    return $members[$i + 1]['grade'];
                }
            }
        }
		include_once IA_ROOT . '/addons/zh_gjw/cert/WxPay.Api.php';
		load()->model('account');
		load()->func('communication');
		$WxPayApi = new WxPayApi();
		$input = new WxPayRefund();
		$path_cert = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_cert_' . $_W['uniacid'] . '.pem';
		$path_key = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
		$refund_order=pdo_get('zh_gjw_reputationrecord',array('id'=>$_GPC['id']));
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
        $appid=$res['appid'];
        $key=$res['apikey'];
        $mchid=$res['mac_id'];
        $out_trade_no=$refund_order['paycode'];//商户订单号
        $res_fee=$refund_order['money'];
        $fee = $res_fee*100;
        $input->SetAppid($appid);
        $input->SetMch_id($mchid);
        $input->SetOp_user_id($mchid);
        $input->SetRefund_fee($fee);
        $input->SetTotal_fee($fee);
        $input->SetOut_refund_no($refund_order['paycode']);
        $input->SetOut_trade_no($out_trade_no);
        $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key);
        if ($result['result_code'] == 'SUCCESS') {//退款成功
          	$ok=pdo_update('zh_gjw_reputationrecord',array('pay'=>3),array('id'=>$_GPC['id']));
        	if ($ok) {
              	$allmoney = pdo_get('zh_gjw_reputationrecord', array('pay' => 2,'openid' => $refund_order['openid'], 'uniacid' => $_W['uniacid']), array('sum(money) as total_money'));
				$store = pdo_getall('zh_gjw_reputation', array('uniacid' => $_W['uniacid']), array(), '', 'money DESC');
		        $storename = getGrade($store, $allmoney['total_money']);
		    	pdo_update('zh_gjw_cusmanage',array('reputation'=>$storename),array('openid'=>$refund_order['openid']));
				echo json_encode(array('msg'=>'成功','code'=>'200'),320);exit();
			}
			echo json_encode(array('msg'=>'失败','code'=>'500'),320);exit();
        }
	}
  	
	//信誉之抖宝发布、推荐剩余
	public function doPageRepucostdbf(){
		global $_GPC, $_W;

		$pubdbnums=pdo_get('zh_gjw_reputationrecord', array('pay' => 2,'openid' => $_GPC['openid'], 'uniacid' => $_W['uniacid']), array('sum(pubdbnum) as pubdbnums','sum(upnum) as upnums'));

		$wheres=' WHERE  uniacid=:uniacid and type=:type and openid=:openid ';
		$datas[':uniacid']=$_W['uniacid'];
		$datas[':type']=1;
		$datas[':openid']=$_GPC['openid'];
		$sql=pdo_fetchall("SELECT SUM(number) as numbers FROM ".tablename('zh_gjw_repucost').$wheres." and DATE(time) =CURDATE()",$datas);
      	
      	$where=' WHERE  uniacid=:uniacid and type=:type and openid=:openid ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':type']=7;
		$data[':openid']=$_GPC['openid'];
		$upnums=pdo_fetchall("SELECT SUM(number) as numbers FROM ".tablename('zh_gjw_repucost').$where." and DATE(time) =CURDATE()",$data);
      	
      	$rest=$pubdbnums['pubdbnums']-$sql[0]['numbers'];
      	$restup=$pubdbnums['upnums']-$upnums[0]['numbers'];
		echo json_encode(array('msg'=>'成功','code'=>'200','pubdbnums'=>$pubdbnums,'numbers'=>$sql,'upnums'=>$upnums,'rest'=>$rest,'restup'=>$restup),320);exit();
	}
  	
	//商家是否买过信誉
	public function doPageRecostis(){
		global $_GPC, $_W;
		$where=' WHERE uniacid=:uniacid and openid=:openid and pay=:pay ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':openid']=$_GPC['openid'];
		$data[':pay']=2;
  		$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_reputationrecord').$where." ORDER BY timesjc desc",$data);
  		echo json_encode(array('msg'=>'成功','code'=>'200','total'=>$total),320);exit();
	}
  	
	//信誉之抖宝推荐、置顶剩余
	public function doPageRepucostdbut(){
		global $_GPC, $_W;

		$dbuts=pdo_get('zh_gjw_reputationrecord', array('pay' => 2,'openid' => $_GPC['openid'], 'uniacid' => $_W['uniacid']), array('sum(upnum) as upnums','sum(topnum) as topnums'));

		$wheres=' WHERE  uniacid=:uniacid and type=:type and openid=:openid ';
		$datas[':uniacid']=$_W['uniacid'];
		$datas[':type']=7;
		$datas[':openid']=$_GPC['openid'];
		$dbups=pdo_fetchall("SELECT SUM(number) as numbers FROM ".tablename('zh_gjw_repucost').$wheres." and DATE(time) =CURDATE()",$datas);
      	
      	$where=' WHERE  uniacid=:uniacid and type=:type and openid=:openid ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':type']=8;
		$data[':openid']=$_GPC['openid'];
		$dbtops=pdo_fetchall("SELECT SUM(number) as numbers FROM ".tablename('zh_gjw_repucost').$where." and DATE(time) =CURDATE()",$data);
      	
      	$restups=$dbuts['upnums']-$dbups[0]['numbers'];
      	$resttops=$dbuts['topnums']-$dbtops[0]['numbers'];
		echo json_encode(array('msg'=>'成功','code'=>'200','dbuts'=>$dbuts,'dbups'=>$dbups,'dbtops'=>$dbtops,'restups'=>$restups,'resttops'=>$resttops),320);exit();
	}
  	
	//信誉之微拍发布、推荐剩余
	public function doPageRepucostshotf(){
		global $_GPC, $_W;
		$pubwpnums=pdo_get('zh_gjw_reputationrecord', array('pay' => 2,'openid' => $_GPC['openid'], 'uniacid' => $_W['uniacid']), array('sum(pubwpnum) as pubwpnums','sum(upnum) as upnums'));

		$wheres=' WHERE  uniacid=:uniacid and type=:type and openid=:openid ';
		$datas[':uniacid']=$_W['uniacid'];
		$datas[':type']=2;
		$datas[':openid']=$_GPC['openid'];
		$wpnums=pdo_fetchall("SELECT SUM(number) as numbers FROM ".tablename('zh_gjw_repucost').$wheres." and DATE(time) =CURDATE()",$datas);
      	
      	$where=' WHERE  uniacid=:uniacid and type=:type and openid=:openid ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':type']=9;
		$data[':openid']=$_GPC['openid'];
		$upnums=pdo_fetchall("SELECT SUM(number) as numbers FROM ".tablename('zh_gjw_repucost').$where." and DATE(time) =CURDATE()",$data);
      	
      	$rest=$pubwpnums['pubwpnums']-$wpnums[0]['numbers'];
      	$restup=$pubwpnums['upnums']-$upnums[0]['numbers'];
		echo json_encode(array('msg'=>'成功','code'=>'200','pubwpnums'=>$pubwpnums,'wpnums'=>$wpnums,'upnums'=>$upnums,'rest'=>$rest,'restup'=>$restup),320);exit();
	}
	//信誉之微拍推荐、置顶剩余
	public function doPageRepucostshotut(){
		global $_GPC, $_W;

		$wputs=pdo_get('zh_gjw_reputationrecord', array('pay' => 2,'openid' => $_GPC['openid'], 'uniacid' => $_W['uniacid']), array('sum(upnum) as upnums','sum(topnum) as topnums'));

		$wheres=' WHERE  uniacid=:uniacid and type=:type and openid=:openid ';
		$datas[':uniacid']=$_W['uniacid'];
		$datas[':type']=9;
		$datas[':openid']=$_GPC['openid'];
		$wpups=pdo_fetchall("SELECT SUM(number) as numbers FROM ".tablename('zh_gjw_repucost').$wheres." and DATE(time) =CURDATE()",$datas);
      	
      	$where=' WHERE  uniacid=:uniacid and type=:type and openid=:openid ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':type']=10;
		$data[':openid']=$_GPC['openid'];
		$wptops=pdo_fetchall("SELECT SUM(number) as numbers FROM ".tablename('zh_gjw_repucost').$where." and DATE(time) =CURDATE()",$data);
      	
      	$restups=$wputs['upnums']-$wpups[0]['numbers'];
      	$resttops=$wputs['topnums']-$wptops[0]['numbers'];
		echo json_encode(array('msg'=>'成功','code'=>'200','wputs'=>$wputs,'wpups'=>$wpups,'wptops'=>$wptops,'restups'=>$restups,'resttops'=>$resttops),320);exit();
	}
  	

	//信誉之地摊发布、推荐剩余
	public function doPageRepucostmarketf(){
		global $_GPC, $_W;
		$pubjsnums=pdo_get('zh_gjw_reputationrecord', array('pay' => 2,'openid' => $_GPC['openid'], 'uniacid' => $_W['uniacid']), array('sum(pubjsnum) as pubjsnums','sum(upnum) as upnums'));

		$wheres=' WHERE  uniacid=:uniacid and type=:type and openid=:openid ';
		$datas[':uniacid']=$_W['uniacid'];
		$datas[':type']=3;
		$datas[':openid']=$_GPC['openid'];
		$jsnums=pdo_fetchall("SELECT SUM(number) as numbers FROM ".tablename('zh_gjw_repucost').$wheres." and DATE(time) =CURDATE()",$datas);
      	
      	$where=' WHERE  uniacid=:uniacid and type=:type and openid=:openid ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':type']=11;
		$data[':openid']=$_GPC['openid'];
		$upnums=pdo_fetchall("SELECT SUM(number) as numbers FROM ".tablename('zh_gjw_repucost').$where." and DATE(time) =CURDATE()",$data);
      	
      	$rest=$pubjsnums['pubwpnums']-$jsnums[0]['numbers'];
      	$restup=$pubjsnums['upnums']-$upnums[0]['numbers'];
		echo json_encode(array('msg'=>'成功','code'=>'200','pubjsnums'=>$pubjsnums,'jsnums'=>$jsnums,'upnums'=>$upnums,'rest'=>$rest,'restup'=>$restup),320);exit();
	}
	//信誉之地摊推荐、置顶剩余
	public function doPageRepucostmarketut(){
		global $_GPC, $_W;

		$jsuts=pdo_get('zh_gjw_reputationrecord', array('pay' => 2,'openid' => $_GPC['openid'], 'uniacid' => $_W['uniacid']), array('sum(upnum) as upnums','sum(topnum) as topnums'));

		$wheres=' WHERE  uniacid=:uniacid and type=:type and openid=:openid ';
		$datas[':uniacid']=$_W['uniacid'];
		$datas[':type']=11;
		$datas[':openid']=$_GPC['openid'];
		$jsups=pdo_fetchall("SELECT SUM(number) as numbers FROM ".tablename('zh_gjw_repucost').$wheres." and DATE(time) =CURDATE()",$datas);
      	
      	$where=' WHERE  uniacid=:uniacid and type=:type and openid=:openid ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':type']=12;
		$data[':openid']=$_GPC['openid'];
		$jstops=pdo_fetchall("SELECT SUM(number) as numbers FROM ".tablename('zh_gjw_repucost').$where." and DATE(time) =CURDATE()",$data);
      	
      	$restups=$jsuts['upnums']-$jsups[0]['numbers'];
      	$resttops=$jsuts['topnums']-$jstops[0]['numbers'];
		echo json_encode(array('msg'=>'成功','code'=>'200','jsuts'=>$jsuts,'jsups'=>$jsups,'jstops'=>$jstops,'restups'=>$restups,'resttops'=>$resttops),320);exit();
	}

	//信誉之商城发布、推荐剩余
	public function doPageRepucoststoresf(){
		global $_GPC, $_W;
		$pubscnums=pdo_get('zh_gjw_reputationrecord', array('pay' => 2,'openid' => $_GPC['openid'], 'uniacid' => $_W['uniacid']), array('sum(pubscnum) as pubscnums','sum(upnum) as upnums'));

		$wheres=' WHERE  uniacid=:uniacid and type=:type and openid=:openid ';
		$datas[':uniacid']=$_W['uniacid'];
		$datas[':type']=4;
		$datas[':openid']=$_GPC['openid'];
		$scnums=pdo_fetchall("SELECT SUM(number) as numbers FROM ".tablename('zh_gjw_repucost').$wheres." and DATE(time) =CURDATE()",$datas);
      	
      	$where=' WHERE  uniacid=:uniacid and type=:type and openid=:openid ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':type']=13;
		$data[':openid']=$_GPC['openid'];
		$upnums=pdo_fetchall("SELECT SUM(number) as numbers FROM ".tablename('zh_gjw_repucost').$where." and DATE(time) =CURDATE()",$data);
      	
      	$rest=$pubscnums['pubwpnums']-$scnums[0]['numbers'];
      	$restup=$pubscnums['upnums']-$upnums[0]['numbers'];
		echo json_encode(array('msg'=>'成功','code'=>'200','pubscnums'=>$pubscnums,'scnums'=>$scnums,'upnums'=>$upnums,'rest'=>$rest,'restup'=>$restup),320);exit();
	}
	//信誉之商城推荐、置顶剩余
	public function doPageRepucoststoresut(){
		global $_GPC, $_W;

		$scuts=pdo_get('zh_gjw_reputationrecord', array('pay' => 2,'openid' => $_GPC['openid'], 'uniacid' => $_W['uniacid']), array('sum(upnum) as upnums','sum(topnum) as topnums'));

		$wheres=' WHERE  uniacid=:uniacid and type=:type and openid=:openid ';
		$datas[':uniacid']=$_W['uniacid'];
		$datas[':type']=13;
		$datas[':openid']=$_GPC['openid'];
		$scups=pdo_fetchall("SELECT SUM(number) as numbers FROM ".tablename('zh_gjw_repucost').$wheres." and DATE(time) =CURDATE()",$datas);
      	
      	$where=' WHERE  uniacid=:uniacid and type=:type and openid=:openid ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':type']=14;
		$data[':openid']=$_GPC['openid'];
		$sctops=pdo_fetchall("SELECT SUM(number) as numbers FROM ".tablename('zh_gjw_repucost').$where." and DATE(time) =CURDATE()",$data);
      	
      	$restups=$scuts['upnums']-$scups[0]['numbers'];
      	$resttops=$scuts['topnums']-$sctops[0]['numbers'];
		echo json_encode(array('msg'=>'成功','code'=>'200','scuts'=>$scuts,'scups'=>$scups,'sctops'=>$sctops,'restups'=>$restups,'resttops'=>$resttops),320);exit();
	}
  	


	//信誉之为您定制发布、推荐剩余
	public function doPageRepucostforyouf(){
		global $_GPC, $_W;
		$pubcunums=pdo_get('zh_gjw_reputationrecord', array('pay' => 2,'openid' => $_GPC['openid'], 'uniacid' => $_W['uniacid']), array('sum(pubcunum) as pubcunums','sum(upnum) as upnums'));

		$wheres=' WHERE  uniacid=:uniacid and type=:type and openid=:openid ';
		$datas[':uniacid']=$_W['uniacid'];
		$datas[':type']=5;
		$datas[':openid']=$_GPC['openid'];
		$cunums=pdo_fetchall("SELECT SUM(number) as numbers FROM ".tablename('zh_gjw_repucost').$wheres." and DATE(time) =CURDATE()",$datas);
      	
      	$where=' WHERE  uniacid=:uniacid and type=:type and openid=:openid ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':type']=15;
		$data[':openid']=$_GPC['openid'];
		$upnums=pdo_fetchall("SELECT SUM(number) as numbers FROM ".tablename('zh_gjw_repucost').$where." and DATE(time) =CURDATE()",$data);
      	
      	$rest=$pubcunums['pubcunums']-$cunums[0]['numbers'];
      	$restup=$pubcunums['upnums']-$upnums[0]['numbers'];
		echo json_encode(array('msg'=>'成功','code'=>'200','pubcunums'=>$pubcunums,'cunums'=>$cunums,'upnums'=>$upnums,'rest'=>$rest,'restup'=>$restup),320);exit();
	}
	//信誉之为您定制推荐、置顶剩余
	public function doPageRepucostforyouut(){
		global $_GPC, $_W;

		$cuuts=pdo_get('zh_gjw_reputationrecord', array('pay' => 2,'openid' => $_GPC['openid'], 'uniacid' => $_W['uniacid']), array('sum(upnum) as upnums','sum(topnum) as topnums'));

		$wheres=' WHERE  uniacid=:uniacid and type=:type and openid=:openid ';
		$datas[':uniacid']=$_W['uniacid'];
		$datas[':type']=15;
		$datas[':openid']=$_GPC['openid'];
		$cuups=pdo_fetchall("SELECT SUM(number) as numbers FROM ".tablename('zh_gjw_repucost').$wheres." and DATE(time) =CURDATE()",$datas);
      	
      	$where=' WHERE  uniacid=:uniacid and type=:type and openid=:openid ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':type']=16;
		$data[':openid']=$_GPC['openid'];
		$cutops=pdo_fetchall("SELECT SUM(number) as numbers FROM ".tablename('zh_gjw_repucost').$where." and DATE(time) =CURDATE()",$data);
      	
      	$restups=$cuuts['upnums']-$cuups[0]['numbers'];
      	$resttops=$cuuts['topnums']-$cutops[0]['numbers'];
		echo json_encode(array('msg'=>'成功','code'=>'200','cuuts'=>$cuuts,'cuups'=>$cuups,'cutops'=>$cutops,'restups'=>$restups,'resttops'=>$resttops),320);exit();
	}
  	
	//信誉之我要定制发布、推荐剩余
	public function doPageRepucostiwantf(){
		global $_GPC, $_W;
		$pubusnums=pdo_get('zh_gjw_reputationrecord', array('pay' => 2,'openid' => $_GPC['openid'], 'uniacid' => $_W['uniacid']), array('sum(pubusnum) as pubusnums','sum(upnum) as upnums'));

		$wheres=' WHERE  uniacid=:uniacid and type=:type and openid=:openid ';
		$datas[':uniacid']=$_W['uniacid'];
		$datas[':type']=6;
		$datas[':openid']=$_GPC['openid'];
		$usnums=pdo_fetchall("SELECT SUM(number) as numbers FROM ".tablename('zh_gjw_repucost').$wheres." and DATE(time) =CURDATE()",$datas);
      	
      	$where=' WHERE  uniacid=:uniacid and type=:type and openid=:openid ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':type']=17;
		$data[':openid']=$_GPC['openid'];
		$upnums=pdo_fetchall("SELECT SUM(number) as numbers FROM ".tablename('zh_gjw_repucost').$where." and DATE(time) =CURDATE()",$data);
      	
      	$rest=$pubusnums['pubusnums']-$usnums[0]['numbers'];
      	$restup=$pubusnums['upnums']-$upnums[0]['numbers'];
		echo json_encode(array('msg'=>'成功','code'=>'200','pubusnums'=>$pubusnums,'usnums'=>$usnums,'upnums'=>$upnums,'rest'=>$rest,'restup'=>$restup),320);exit();
	}
	//信誉之我要定制推荐、置顶剩余
	public function doPageRepucostiwantut(){
		global $_GPC, $_W;

		$usuts=pdo_get('zh_gjw_reputationrecord', array('pay' => 2,'openid' => $_GPC['openid'], 'uniacid' => $_W['uniacid']), array('sum(upnum) as upnums','sum(topnum) as topnums'));

		$wheres=' WHERE  uniacid=:uniacid and type=:type and openid=:openid ';
		$datas[':uniacid']=$_W['uniacid'];
		$datas[':type']=17;
		$datas[':openid']=$_GPC['openid'];
		$usups=pdo_fetchall("SELECT SUM(number) as numbers FROM ".tablename('zh_gjw_repucost').$wheres." and DATE(time) =CURDATE()",$datas);
      	
      	$where=' WHERE  uniacid=:uniacid and type=:type and openid=:openid ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':type']=18;
		$data[':openid']=$_GPC['openid'];
		$ustops=pdo_fetchall("SELECT SUM(number) as numbers FROM ".tablename('zh_gjw_repucost').$where." and DATE(time) =CURDATE()",$data);
      	
      	$restups=$usuts['upnums']-$usups[0]['numbers'];
      	$resttops=$usuts['topnums']-$ustops[0]['numbers'];
		echo json_encode(array('msg'=>'成功','code'=>'200','usuts'=>$usuts,'usups'=>$usups,'ustops'=>$ustops,'restups'=>$restups,'resttops'=>$resttops),320);exit();
	}
  	
	//用户需不需要付系统保证金
	public function doPageSysbzj(){
		global $_GPC, $_W;
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid']));
		$where=' WHERE uniacid=:uniacid and u_id=:u_id and sysbzj=:sysbzj ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':u_id']=$user['id'];
		$data[':sysbzj']=1;
  		$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_balance').$where." ORDER BY id ASC",$data);
		$sysbzj=pdo_get('zh_gjw_sysbzj',array('pay'=>2,'u_id'=>$user['id']));
		if ($sysbzj) {
			$pay=2;
		}else{
			$pay=1;
		}
  		echo json_encode(array('msg'=>'成功','code'=>'200','total'=>$total,'pay'=>$pay),320);exit();
	}
  	
  	
	//支付系统保证金
	public function doPageSysbzjpay(){
		global $_W,$_GPC;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid']));
		$sysbzj=pdo_get('zh_gjw_sysbzj',array('u_id'=>$user['id']));
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		if (empty($sysbzj)) {
			$data['u_id']=$user['id'];
			$data['paycode']=$out_trade_no;
			$data['formid']=$_GPC['formid'];
			$data['fee']=$res['sysbzj'];
			$data['pay']=1;
			$data['uniacid']=$_W['uniacid'];
			$data['time']=date('Y-m-d H:i:s',time());
			$insert=pdo_insert('zh_gjw_sysbzj',$data);
			$res_id=pdo_insertid();
		}else{
			pdo_update('zh_gjw_sysbzj', array('paycode' =>$out_trade_no,'fee' =>$res['sysbzj'],'formid' =>$_GPC['formid'],'time'=>date('Y-m-d H:i:s',time())), array('id' =>$sysbzj['id']));
			$res_id=$sysbzj['id'];
		}
		$root=$_W['siteroot']; 
		$total_fee =$res['sysbzj'];
		if($total_fee>0)
		{
			$body = "系统保证金支付";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
      	$return['res_id']=$res_id;
		echo json_encode($return);
	}
  	//支付系统保证金成功改变状态
	public function doPageSysbzjpaysuccess(){
		global $_W, $_GPC;
		$res = pdo_update('zh_gjw_sysbzj', array('pay' =>2,'time'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id']));
		if ($res) {
			echo json_encode(array('msg'=>'好了','code'=>'200'),320);exit();
		}
		echo json_encode(array('msg'=>'错了','code'=>'500'),320);exit();
	}
  	//用户需不需要付系统保证金地摊
	public function doPageSysbzjd(){
		global $_GPC, $_W;
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid']));
		$where=' WHERE uniacid=:uniacid and u_id=:u_id and tole=:tole and pay=:pay ';
		$data[':uniacid']=$_W['uniacid'];
		$data[':u_id']=$user['id'];
		$data[':tole']=1;
		$data[':pay']=0;
  		$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_marketbuy').$where." ORDER BY id ASC",$data);
		$sysbzj=pdo_get('zh_gjw_sysbzjd',array('pay'=>2,'u_id'=>$user['id']));
		if ($sysbzj) {
			$pay=2;
		}else{
			$pay=1;
		}
  		echo json_encode(array('msg'=>'成功','code'=>'200','total'=>$total,'pay'=>$pay),320);exit();
	}
  	
  	
	//支付系统保证金地摊
	public function doPageSysbzjpayd(){
		global $_W,$_GPC;
		include IA_ROOT.'/addons/zh_gjw/wxpay.php';
		$res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
		$user=pdo_get('zh_gjw_register',array('openid'=>$_GPC['openid']));
		$sysbzj=pdo_get('zh_gjw_sysbzjd',array('u_id'=>$user['id']));
		$appid=$res['appid'];
		$openid=$_GPC['openid'];
		$mch_id=$res['mac_id'];
		$key=$res['apikey'];
		$out_trade_no = $mch_id. time();
		if (empty($sysbzj)) {
			$data['u_id']=$user['id'];
			$data['paycode']=$out_trade_no;
			$data['formid']=$_GPC['formid'];
			$data['fee']=$res['sysbzj'];
			$data['pay']=1;
			$data['uniacid']=$_W['uniacid'];
			$data['time']=date('Y-m-d H:i:s',time());
			$insert=pdo_insert('zh_gjw_sysbzjd',$data);
			$res_id=pdo_insertid();
		}else{
			pdo_update('zh_gjw_sysbzjd', array('paycode' =>$out_trade_no,'fee' =>$res['sysbzj'],'formid' =>$_GPC['formid'],'time'=>date('Y-m-d H:i:s',time())), array('id' =>$sysbzj['id']));
			$res_id=$sysbzj['id'];
		}
		$root=$_W['siteroot']; 
		$total_fee =$res['sysbzj'];
		if($total_fee>0)
		{
			$body = "系统保证金支付";
			$total_fee = floatval($total_fee*100);
		}
		$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
		$return=$weixinpay->pay();
      	$return['res_id']=$res_id;
		echo json_encode($return);
	}
  	//支付系统保证金成功改变状态地摊
	public function doPageSysbzjpaysuccessd(){
		global $_W, $_GPC;
		$res = pdo_update('zh_gjw_sysbzjd', array('pay' =>2,'time'=>date('Y-m-d H:i:s',time())), array('id' =>$_GPC['res_id']));
		if ($res) {
			echo json_encode(array('msg'=>'好了','code'=>'200'),320);exit();
		}
		echo json_encode(array('msg'=>'错了','code'=>'500'),320);exit();
	}
  /**
  *isvideo
  */
  public function doPageIsvideo(){
    global $_W;
    $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
    echo json_encode(array('msg'=>'获取成功','code'=>'200','res'=>$res['isvideo']),320);exit();
  }
  /**
  *隐藏底部菜单
  */
  public function doPageMenuset(){
    global $_W;
    $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
    echo json_encode(array('msg'=>'获取成功','code'=>'200','db'=>$res['db'],'wp'=>$res['wp'],'dt'=>$res['dt'],'sc'=>$res['sc'],'dz'=>$res['dz']),320);exit();
  }
  
}